C语言学生成绩管理程序
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
int i; for(i=0;i<10;i++) { ave1=ave1+stu[i].score[0]; ave2=ave2+stu[i].score[1]; ave3=ave3+stu[i].score[2]; } ave1=ave1/10; ave2=ave2/10; ave3=ave3/10; } void scort()//根据三门课的平均分排序 选择法排序 { int i,j,k,temp,h; char na[20]; double av,su,sc[3]; for(i=0;i<9;i++) { k=i; for(j=i+1;j<10;j++) if(stu[j].average>stu[k].average) k=j; if(i!=k) { av=stu[i].average;stu[i].average=stu[k].average;stu[k].average=av; strcpy(na,stu[i].name);strcpy(stu[i].name,stu[k].name);strcpy(stu[k].name,na); temp=stu[i].number;stu[i].number=stu[k].number;stu[k].number=temp; su=stu[i].sum;stu[i].sum=stu[k].sum;stu[k].sum=su; for(h=0;h<3;h++) { sc[h]=stu[i].score[h]; stu[i].score[h]=stu[k].score[h]; stu[k].score[h]=sc[h]; }
#include <stdio.h> #include <string.h> struct student { int number;//学号 double sum;//三门课的总成绩 double average;//三门课的平均分 char name[20];//学生姓名 double score[3];//三门课的成绩 }; student stu[10];//定义10个结构体对象 double ave1=0,ave2=0,ave3=0;//0个学生的每门课的平均分 void input()//输入10个学生的信息的函数 { int i,j; for(i=0;i<10;i++) { scanf("%d",&stu[i].number);//输入学号 scanf("%s",stu[i].name);//输入姓名 for(j=0;j<3;j++)//输入三门成绩 scanf("%lf",&stu[i].score[j]); } } void average1()//求每个学生的三门课的平均分的函数 { int k,j; for(k=0;k<10;k++) { stu[k].sum=0; for(j=0;j<3;j++) stu[k].sum=stu[k].score[j]+stu[k].sum; stu[k].average=stu[k].sum/3; } } void average2()//求10个学生的每门课的平均分 {
ቤተ መጻሕፍቲ ባይዱ
} } } void output()//输出排名后的信息 { int i,j; printf("the first course average of the 10 students is:%0.2lf\n",ave1); printf("the second course average of the 10 students is:%0.2lf\n",ave2); printf("the third course average of the 10 students is :%0.2lf\n",ave3); printf("After the ranking:\n"); for(i=0;i<10;i++) { printf("Rank %d",i+1);//排名 printf(" studentnumber:%d studentname:%s the average of the three course is:%0.2lf\n",stu[i].number,stu[i].name,stu[i].average); printf("the total score of the three course is:%0.2lf\n",stu[i].sum); printf("the score of the three course is: "); for(j=0;j<3;j++) { printf("%0.2lf ",stu[i].score[j]); } printf("\n\n"); } } void main() { printf("please intput 10 students information\nstudentnumber,studentname,the score of three course\n"); input(); average1(); average2(); scort(); output(); }