猿问

这个C语言程序怎么改才对?

#include <stdio.h>

/*输入10个学生5门课的成绩,分别用函数求:①每个学生平均分;②每门课的平均分;③找出最高的分数所对应的学生和课程。


实验要求:输入事先已编好的程序,并运行该程序。分析运行结果是否正确。 */

#define x 10

#define y 5

float stu_average(int mark[x][y]);

void score_average(int score[x][y]);

int highest(float ave[x]);

int main()

{

int a[x][y];

float ave[x];

int i=0,j=0,num;

for(i=0;i<x;i++)

{

for(j=0;j<y;j++){scanf("%d",&a[i][j]);}

}



printf("Part 1: the averages of every student\n");//10个学生平均分

for(j=0;j<x;j++)

{

ave[j]=stu_average(a);

printf("%.6f\n",ave[j]);

}


printf("Part 2: the averages of every course score\n");//5门课程平均分

for(j=0;j<y;j++)

score_average(ave);


printf("Part 3: a student  and  course scores of the student whose average is the highest\n");//最高分数

num=highest(ave);

printf("%d\n",num+1);

printf("%d %d %d %d %d",a[num+1][0],a[num+1][1],a[num+1][2],a[num+1][3],a[num+1][4]);

return 0;

}



float stu_average(int mark[x][y])

{

    float average;

int m=0,n=0,sum;

for(m=0;m<x;m++)

{

for(n=0;n<y;n++){sum+=mark[m][n];}

average=(float)sum/5.0;

return average;

sum=0;

}

}



void score_average(int score[x][y])

{

int i=0,j=0,sum;

float average[x];

for(i=0;i<y;i++)

{

for(j=0;j<x;j++){sum+=score[j][i];}

average[i]=(float)sum/10.0;

printf("%.6f\n",average[i]);

sum=0;

}

}



int highest(float ave[x])

{

int i,j=0;

float max;

float find_max[10]={ave[0],ave[1],ave[2],ave[3],ave[4],ave[5],ave[6],ave[7],ave[8],ave[9]};

max=find_max[0];

for(i=0;i<x;i++)

{

 if(max<=find_max[i])

 max=find_max[i];

 j=i;

}

return (j+1);

}

错误:

C:\Users\Administrator\Desktop\c\Text2.c(2) : error C2006: #include expected a filename, found 'newline'

C:\Users\Administrator\Desktop\c\Text2.c(5) : error C2054: expected '(' to follow 'include'

C:\Users\Administrator\Desktop\c\Text2.c(6) : error C2085: 'average' : not in formal parameter list

C:\Users\Administrator\Desktop\c\Text2.c(6) : error C2143: syntax error : missing ';' before '{'

C:\Users\Administrator\Desktop\c\Text2.c(20) : warning C4013: 'printf' undefined; assuming extern returning int

C:\Users\Administrator\Desktop\c\Text2.c(21) : error C2143: syntax error : missing ';' before '{'

C:\Users\Administrator\Desktop\c\Text2.c(21) : error C2143: syntax error : missing ')' before '{'

C:\Users\Administrator\Desktop\c\Text2.c(21) : error C2146: syntax error : missing ';' before identifier 'ave'

C:\Users\Administrator\Desktop\c\Text2.c(21) : error C2143: syntax error : missing ')' before ';'

C:\Users\Administrator\Desktop\c\Text2.c(28) : error C2143: syntax error : missing ';' before 'for'

C:\Users\Administrator\Desktop\c\Text2.c(28) : error C2143: syntax error : missing ')' before 'for'

C:\Users\Administrator\Desktop\c\Text2.c(28) : error C2143: syntax error : missing ';' before 'if'

C:\Users\Administrator\Desktop\c\Text2.c(28) : error C2143: syntax error : missing ')' before 'if'

C:\Users\Administrator\Desktop\c\Text2.c(28) : error C2146: syntax error : missing ')' before identifier 'printf'

C:\Users\Administrator\Desktop\c\Text2.c(34) : error C2146: syntax error : missing ';' before identifier 'xi'

C:\Users\Administrator\Desktop\c\Text2.c(34) : error C2143: syntax error : missing ')' before ';'

C:\Users\Administrator\Desktop\c\Text2.c(36) : error C2146: syntax error : missing ';' before identifier 'd'

C:\Users\Administrator\Desktop\c\Text2.c(36) : warning C4013: 'pow' undefined; assuming extern returning int

C:\Users\Administrator\Desktop\c\Text2.c(36) : error C2143: syntax error : missing ')' before ';'

C:\Users\Administrator\Desktop\c\Text2.c(40) : error C2006: #include expected a filename, found 'newline'

C:\Users\Administrator\Desktop\c\Text2.c(41) : error C2006: #include expected a filename, found 'newline'

C:\Users\Administrator\Desktop\c\Text2.c(42) : error C2006: #include expected a filename, found 'newline'

C:\Users\Administrator\Desktop\c\Text2.c(43) : warning C4005: 'N' : macro redefinition

        C:\Users\Administrator\Desktop\c\Text2.c(3) : see previous definition of 'N'

C:\Users\Administrator\Desktop\c\Text2.c(44) : warning C4005: 'M' : macro redefinition

        C:\Users\Administrator\Desktop\c\Text2.c(4) : see previous definition of 'M'

C:\Users\Administrator\Desktop\c\Text2.c(46) : warning C4028: formal parameter 1 different from declaration

C:\Users\Administrator\Desktop\c\Text2.c(47) : warning C4028: formal parameter 1 different from declaration

C:\Users\Administrator\Desktop\c\Text2.c(52) : error C2065: 'new' : undeclared identifier

C:\Users\Administrator\Desktop\c\Text2.c(52) : warning C4047: 'initializing' : 'float *' differs in levels of indirection from 'int '

C:\Users\Administrator\Desktop\c\Text2.c(52) : error C2143: syntax error : missing ';' before 'type'

C:\Users\Administrator\Desktop\c\Text2.c(52) : warning C4091: ' ' : ignored on left of 'float ' when no variable is declared

C:\Users\Administrator\Desktop\c\Text2.c(58) : error C2146: syntax error : missing ';' before identifier 'scanf'

C:\Users\Administrator\Desktop\c\Text2.c(58) : warning C4013: 'scanf' undefined; assuming extern returning int

C:\Users\Administrator\Desktop\c\Text2.c(58) : error C2143: syntax error : missing ')' before ';'

C:\Users\Administrator\Desktop\c\Text2.c(62) : error C2143: syntax error : missing ';' before '{'

C:\Users\Administrator\Desktop\c\Text2.c(62) : error C2143: syntax error : missing ')' before '{'

C:\Users\Administrator\Desktop\c\Text2.c(62) : error C2146: syntax error : missing ';' before identifier 'printf'

C:\Users\Administrator\Desktop\c\Text2.c(62) : error C2143: syntax error : missing ')' before ';'

C:\Users\Administrator\Desktop\c\Text2.c(69) : fatal error C1004: unexpected end of file found

执行 cl.exe 时出错.

Text2.exe - 1 error(s), 0 warning(s)

之前改了,输入的数据的出来的结果也不正确 

求大神

子非漁
浏览 3051回答 1
1回答

Tanh

#include <stdio.h> /*输入10个学生5门课的成绩,分别用函数求:①每个学生平均分;②每门课的平均分;③找出最高的分数所对应的学生和课程。 实验要求:输入事先已编好的程序,并运行该程序。分析运行结果是否正确。 */ #define x 10 #define y 5 float stu_average(int mark[x][y]); void score_average(int score[x][y]); int highest(float ave[x]); int main() { int a[x][y]; float ave[x]; int i=0,j=0,num; printf("输入10位学生的5门课程成绩.\n"); for(i=0;i<x;i++) { printf("输入第%d位学生的5门课程成绩.\n",i+1); for(j=0;j<y;j++){scanf("%d",&a[i][j]);} } printf("Part 1: the averages of every student\n");//10个学生平均分,该学生平均每门课的成绩 for(j=0;j<x;j++) { stu_average(a); } printf("Part 2: the averages of every course score\n");//5门课程平均分 for(j=0;j<y;j++) { score_average(a); } return 0; } float stu_average(int mark[x][y]) {     float average; int m=0,n=0,sum=0; for(m=0;m<x;m++) { for(n=0;n<y;n++){sum+=mark[m][n];} average=(float)sum/5; printf("%.6f\n",average); return 0; } } void score_average(int score[x][y]) { int m=0,n=0,sum=0; float average; for(n=0;n<y;n++) { for(m=0;m<x;m++){sum+=score[m][n];} average=(float)sum/10; }printf("%.6f\n",average); }
随时随地看视频慕课网APP
我要回答