![C语言程序][1]

最近C语言的作业是编写3名同学的五科成绩的计算,有许多小伙伴都写出来了,自己的程序部分小伙伴没有写出来。我下面给出我自己写的源码,希望能够帮助到一些小伙伴。

这里我给出几点建议:

  1. 下面的代码不建议直接复制粘贴使用,可以尝试去改一下!
  2. 不会的源码里面都有相关的解释和说明!
  3. 编程是一个漫长的过程,需要自己一步步的去编写,而不是直接调用。

代码


#include <stdio.h>
int main()
{
float score1,score2,score3,score4,score5,score6,score7,score8,
score9,score10,score11,score12,score13,score14,score15,score16,score17,
avg1,avg2,avg3,avg4,avg5,avg6,avg7,avg8,avg9,avg10,sum1,sum2,sum3,sum4,sum5,sum6
,sum7,sum8,sum9,sum10,avg11,sum11;
/*上面的float这个函数是定义浮点型的常量,每个常量之间使用英文的逗号隔开,最后使用英文的分号进行结尾 */
printf("\t|-----------学生成绩管理系统--------------------|\n");
printf("\t|1.增加学生记录\t\t\t\t\t|\n"); /*printf这个函数是输出函数,即可在屏幕上显示的内容*/
/*注意这里显示的内容是printf括号双引号里面的内容,而不是整行*/ 
printf("\t|2.修改学生记录\t\t\t\t\t|\n"); 
printf("\t|3.删除学生记录\t\t\t\t\t|\n"); /*\t是空8格,这里不建议大家使用空格键来达到空格的效果*/
printf("\t|4.按姓名查询学生记录\t\t\t\t|\n"); 
printf("\t|5.按平均成绩排序\t\t\t\t|\n"); /*\n是换行,即内容跳到下一行显示 */
printf("\t|6.退出\t\t\t\t\t\t|\n"); 
printf("\t-------------------------------------------------\n"); 
printf("\t|请选择<1-6>:\t\t\t\t\t|\n"); 
printf("\t|请输入学号:\t\t\t\t\t|\n"); 
printf("\t|请输入姓名:\t\t\t\t\t|\n"); 
printf("\t|请输入语文成绩:\t\t\t\t|\n"); 
printf("\t|请输入数学成绩:\t\t\t\t|\n"); 
printf("\t|请输入英语成绩:\t\t\t\t|\n"); 
printf("\t|请输入物理成绩:\t\t\t\t|\n"); 
printf("\t|请输入化学成绩:\t\t\t\t|\n"); 
printf("\t是否继续?<y/n>\t\t\t\t\t|\n"); 
printf("\t---------------------------------------------\n"); 
printf("请输入张三学生的五科成绩,使用英文逗号相隔\n");
scanf("%f,%f,%f,%f,%f",&score1,&score2,&score3,&score4,&score5);
/*这里的scanf是写入函数,就是把上面输入的数据写入进去 */
printf("语文:%5.2f,数学:%5.2f,英语:%5.2f,物理:%5.2f,化学:%5.2f\n",score1,score2,score3,score4,score5);
printf("------------------------------------------------------------------------\n");
printf("请输入李四学生的五科成绩,使用英文逗号相隔\n");
scanf("%f,%f,%f,%f,%f",&score6,&score7,&score8,&score9,&score10);
printf("语文:%5.2f,数学:%5.2f,英语:%5.2f,物理:%5.2f,化学:%5.2f\n",score6,score7,score8,score9,score10);
printf("------------------------------------------------------------------------\n");
printf("请输入王五学生的五科成绩,使用英文逗号相隔\n");
scanf("%f,%f,%f,%f,%f",&score11,&score12,&score13,&score14,&score15);
printf("语文:%5.2f,数学:%5.2f,英语:%5.2f,物理:%5.2f,化学:%5.2f\n",score11,score12,score13,score14,score15);
avg1=(score1+score6+score11)/3;
avg2=(score2+score7+score12)/3;
avg3=(score3+score8+score13)/3;  
avg4=(score4+score9+score14)/3;
avg5=(score5+score10+score15)/3;    
avg6=(score1+score2+score3+score4+score5)/5;
avg7=(score6+score7+score8+score9+score10)/5;
avg8=(score11+score12+score13+score14+score15)/5;
avg9=(avg6+avg7+avg8)/3;
avg10=(avg6+avg7+avg8)/3;
avg11=(sum1+sum2+sum3)/3;
/*上面使用到的都是下面表格需要用到的值,上面是用来计算的 */
sum1=score1+score2+score3+score4+score5;
sum2=score6+score7+score8+score9+score10;
sum3=score11+score12+score13+score14+score15;
sum4=score1+score6+score11;
sum5=score2+score7+score12;
sum6=score3+score8+score13;   
sum7=score4+score9+score14;
sum8=score5+score10+score15;
sum9=sum1+sum2+sum3;
sum10=sum1+sum2+sum3;
sum11=avg1+avg2+avg3+avg4+avg5+avg10;
/*这里是求和的公式 */
printf("-----------------------------学生成绩表----------------------------------\n");
printf("__________________________________________________________________________\n");
printf("|姓名|\t|语文|\t|数学|\t|英语|\t|物理|\t|化学|\t|平均分|\t|总分|\n");
printf("___________________________________________________________________________\n");
printf("|张三|\t|%5.1f|\t|%5.1f|\t|%5.1f|\t|%5.1f|\t|%5.1f|\t|%5.1f|\t\t|%5.1f|\n",score1,score2,score3,score4,score5,avg6,sum1);
printf("____________________________________________________________________________\n");
printf("|李四|\t|%5.1f|\t|%5.1f|\t|%5.1f|\t|%5.1f|\t|%5.1f|\t|%5.1f|\t\t|%5.1f|\n",score6,score7,score8,score9,score10,avg7,sum2);
printf("____________________________________________________________________________\n");
printf("|王五|\t|%5.1f|\t|%5.1f|\t|%5.1f|\t|%5.1f|\t|%5.1f|\t|%5.1f|\t\t|%5.1f|\n",score11,score12,score13,score14,score15,avg8,sum3);
printf("____________________________________________________________________________\n");
printf("|总分|\t|%5.1f|\t|%5.1f|\t|%5.1f|\t|%5.1f|\t|%5.1f|\t|%5.1f|\t\t|%5.1f|\n",sum4,sum5,sum6,sum7,sum8,avg9,sum10);
printf("____________________________________________________________________________\n");
printf("|平均分|\t\b|%5.1f|\t|%5.1f|\t|%5.1f|\t|%5.1f|\t|%5.1f|\t|%5.1f|\t\t|%5.1f|\n",avg1,avg2,avg3,avg4,avg5,avg10,sum11);
printf("____________________________________________________________________________\n");
 /*上面使用到的%f和%5.1f以及%5.2f这几个分别是浮点型数值,5.1和5.2的5是五列,.1和.2分别是保留的位数
 例如.1是保留一位小数,.2是保留两位小数 */   
return 0;
/*这里使用了返回函数,这是因为我上面使用了int mian,如果不想用可以把前面的int去掉就可以了 */

}



----------

> ###`预览`
![预览1][2]![预览2][3]


  [1]: https://oss.wchangc.com/Blog/2019/10/27/470902401410943/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20191025181321.png
  [2]: https://oss.wchangc.com/Blog/2019/10/27/478863397531843/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20191025191319.png
  [3]: https://oss.wchangc.com/Blog/2019/10/27/479112748962841/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20191025191303.png
Last modification:October 27th, 2019 at 03:51 pm
如果觉得我的文章对你有用,请随意赞赏