标题:请 忆楠 大哥帮着看一下C程序,有错误!
取消只看楼主
canniao
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2004-12-14
 问题点数:0 回复次数:2 
请 忆楠 大哥帮着看一下C程序,有错误!

请 忆楠 大哥帮着看一下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"); }

搜索更多相关主题的帖子: function average include 源代码 scores 
2004-12-15 12:41
canniao
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2004-12-14
得分:0 
如果想输出所有有不及格课程的学生的学号、全部课程的成绩、平均成绩;如何修改,谢谢!!辛苦你了!!
2004-12-15 12:43
canniao
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2004-12-14
得分:0 

页面是 C作业解答,斑竹是你,所以就请你了

两位高手回帖,感激不尽。

帮帮小弟,结构体懂,但我是菜鸟。

2004-12-15 23:12



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-9427-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.763098 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved