報錯有點看不懂 就一點點錯誤 麻煩大佬看一下
#include <stdio.h>
int score[10]={67,98,75,63,82,79,81,91,66,84};
? ? int i,j;
? ? ?for(i=8; i>=0;--i)
? ? {
? ? ? ? for(j=0;j<=i;j++)
? ? ? ? {
? ? ? ? ? ? if(arr[j]>arr[j+1]? ? ? ? ? ? )? ? ? //當前面的數比后面的數大時
? ? ? ? ? ? {
? ? ? ? ? ? ? ? double temp;? ? //定義臨時變量temp
? ? ? ? ? ? ? ? temp=arr[j];//將前面的數賦值給temp
? ? ? ? ? ? ? ? arr[j]=arr[j+1];? ? ? ? ? ? ? //前后之數顛倒位置
? ? ? ? ? ? ? ? arr[j+1]=temp;? ? ? ? ? ? ? //將較大的數放在后面? ??
? ? ? ? ? ? }? ? ? ? ? ? ? ? ?
? ? ? ? }? ? ? ? ? ? ? ??
? ? }
int sum=0;
int all()
{
? ? int i;
? ? for(i=0;i<10;i++)
? ? {
? ? ? ? ?sum+=score[i];
? ? }
? ? return sum;
}
double average()
{
? ? return sum/10.0;
}? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
int highest()
{
? ? return score[9];
}
int lowest()
{
? ? return score[0];
}
int main()
{
? ? int a;
? ? printf("總分:%d\n",all());
? ? printf("平均分:%f\n",average());
? ? printf("考試成績降序排列:");
? ? for(a=0;a<10;a++)
? ? {
? ? ? ? if(a=9)
? ? ? ? {
? ? ? ? ? ? printf("%d\n",score[a]);
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? printf("%d,",score[a]);
? ? ? ? }
? ? }
? ? printf("最高分:%d\n",highest());
? ? printf("最低分:%d\n",lowest());
? ? return 0;
}
報錯:
hello.c:4:6: error: expected identifier or '(' before 'for'
? ? ? for(i=8; i>=0;--i)
? ? ? ^~~
hello.c:4:16: error: expected '=', ',', ';', 'asm' or '__attribute__' before '>=' token
? ? ? for(i=8; i>=0;--i)
? ? ? ? ? ? ? ? ^~
hello.c:4:20: error: expected identifier or '(' before '--' token
? ? ? for(i=8; i>=0;--i)
? ? ? ? ? ? ? ? ? ? ^~
2020-08-12
頭文件 定義變量? 常量 數組 結構 可以在函數外面其他應該是不符合規范的
你寫的是沒有參數的函數,也沒有重新定義變量;是不可以直接用的
2020-08-12
引用頭文件 定義變量 常量 數組可以不在函數外面? 但你循環也是寫在函數外面的