请 忆楠 大哥帮着看一下C程序,有错误!
可不可以将修改过后正确的源代码,给我看看呢
#include <stdio.h> #include <conio.h> #define N1 2 #define N2 3 float Stu_Score[N1][N2]; float S_Ave[N1]; float C_Ave[N2]; int A[N2];
/*--------------------function declaration-----------------*/ void print_menu(); void input_score(); /*input students‘ scores*/ void print_s_ave(); /*print students‘ average score */ void stu_ave(); /* count students‘ average score */ void course_ave(); /* count courses‘ average score */ void print_c_ave(); /* print courses‘ average score */ void find_max_course(); /* search the max score */ void fangcha(); /*count the fangcha */
/*------------------------main()---------------------------*/ int main() { char ch;
for(;;){ do{ print_menu(); ch=toupper(getch()); }while (ch!=‘I‘ && ch!=‘S‘ && ch!=‘C‘ && ch!=‘Q‘); switch(ch){ case ‘I‘:input_score(); break; case ‘S‘:stu_ave(); print_s_ave(); break; case ‘C‘:course_ave(); print_c_ave(); break; case ‘Q‘:clrscr(); exit(0); }/* end of switch */ } /* end of for statement */
}
/*------------------------input_score()---------------------*/ void input_score(void) { int i,j; clrscr();
for(i=0;i<N1;i++){ printf("No.%d",i+1); for(j=0;j<N2;j++) scanf("%f",&Stu_Score[i][j]);
} }
/*-------------------------stu_ave()--------------------------*/ void stu_ave(void) {
int i,j;
for (i=0;i<N1;i++ ) S_Ave[i]=0;
for(i=0;i<N1;i++){ for(j=0;j<N2;j++) S_Ave[i]+=Stu_Score[i][j]; S_Ave[i]/=N2; }
}
void print_s_ave(void) { int i;
clrscr();
printf(" the average score table of all students "); printf(" No. ave_score "); for(i=0;i<N1;i++) printf(" No.%d %6.2f ",i,S_Ave[i]); printf("Press any key to return to main menu.... "); getch(); }
/*--------------------------course_ave()-----------------------*/ void course_ave(void) { int i,j;
for (i=0;i<N2;i++ ) C_Ave[i]=0;
for(i=0;i<N2;i++){ for(j=0;j<N1;j++) C_Ave[i]+=Stu_Score[j][i]; C_Ave[i]/=N1; }
}
void print_c_ave(void) { int i; char *name[]={"math","chinese","english","physics","chemistry"};
clrscr();
printf(" the average score table of all courses "); printf(" Course Name ave_score "); for(i=0;i<N2;i++) printf(" %s %6.2f ",name[i],C_Ave[i]); printf("Press any key to return the main menu...... "); getch(); }
/*--------------------------find_max_course()-----------------------*/ void find_max_course(void) { int i,j,t; char *name[]={"math","chinese","english","physics","chemistry"};
clrscr(); for(i=0;i<N2;i++){ t=0; for(j=1;j<N1;j++) if(Stu_Score[t][i]<Stu_Score[j][i]) t=j; printf("%s %d %6.2f ",name[i],t+1,Stu_Score[t][i]);
}
}
/*---------------------------fangcha()---------------------------*/ void fangcha(void) { float s1=0,s2=0,f; int i;
stu_ave(); for(i=0;i<N1;i++){ s1=s1+S_Ave[i]*S_Ave[i]; s2=s2+S_Ave[i]; }
s2/=N1; f=s1/N1-s2*s2;
clrscr(); printf("fangcha is %6.2f",f); }
/*-------------------print_menu()--------------------*/ void print_menu() { clrscr(); textattr(BLUE*16|YELLOW); gotoxy(15,5); cprintf("1.(I)nput Students‘ score"); textattr(BLUE*16|YELLOW); gotoxy(15,9); cprintf("2.(S)tudents‘ average score"); textattr(BLUE*16|YELLOW); gotoxy(15,13); cprintf("3.(C)ourse‘ average score"); textattr(BLUE*16|YELLOW); gotoxy(15,17); cprintf("4.(Q)uit the system"); }