[C]bash:syntax error near unexpected token `('

数组计算平均数,这块代码反复看都看不出问题。输出 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;
}


幕布斯6054654
浏览 1133回答 1
1回答

Qyouu

不是代码的问题, 编译后, 你是怎么执行的?我猜你是没有编译, 直接按脚本去执行了你需要把代码保存 c 文件,如&nbsp;test.c然后用 gcc 编译如$&nbsp;gcc&nbsp;test.c会在当前文件夹下生成一个a.out的可执行文件执行$&nbsp;./a.out会得到你要的结果.
打开App,查看更多内容
随时随地看视频慕课网APP