数组计算平均数,这块代码反复看都看不出问题。输出 bash:syntax error near unexpected token `('
#include <stdio.h>
int main(void)
{
int grades[10];
unsigned int count = 10;
long sum = 0L;
float average = 0.0f;
//printf("\nEnter the number of people in your class:");
//scanf("%u", &count);
for(unsigned int i = 0 ; i < count ; ++i)
{
printf("The grade of class number %2u is", i+1);
scanf("%d", &grades[i]);
sum += grades[i];
}
average = (float)sum/count;
printf("The average grade of the class is: %.2f", average);
return 0;
}
不是代码的问题, 编译后, 你是怎么执行的?
我猜你是没有编译, 直接按脚本去执行了
你需要把代码保存 c 文件,如
test.c
然后用 gcc 编译
如
会在当前文件夹下生成一个
a.out
的可执行文件执行
会得到你要的结果.