数组计算平均数,这块代码反复看都看不出问题。输出 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;
}
1 回答
![?](http://img1.sycdn.imooc.com/545868190001d52602200220-100-100.jpg)
Qyouu
TA贡献1786条经验 获得超11个赞
不是代码的问题, 编译后, 你是怎么执行的?
我猜你是没有编译, 直接按脚本去执行了
你需要把代码保存 c 文件,如 test.c
然后用 gcc 编译
如
$ gcc test.c
会在当前文件夹下生成一个a.out
的可执行文件
执行
$ ./a.out
会得到你要的结果.
- 1 回答
- 0 关注
- 1132 浏览
添加回答
举报
0/150
提交
取消