
哥哥你太浪漫了,这么难得题!
使用结构数组短多啦
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include<stdioh>
struct stuScore
{
char name[20];
int number;
float math;
float comp;
};
void main()
{int i;
float sum[5];
stuScore st[5];
printf("请输入5位学生的学号、姓名、数学成绩、计算机成绩\n");
for(i=0;i<5;i++)
scanf("%d%s%f%f",&st[i]number,st[i]name,&st[i]math,&st[i]comp);
printf("学号\t姓名\t数学\t计算机\t总分\n");
for(i=0;i<5;i++)
{sum[i]=st[i]math+st[i]comp;
printf("%d\t%s\t%62f\t%62f\t%62f\n",st[i]number,st[i]name,st[i]math,st[i]comp,sum[i]);
}
}
使用结构变量,没有使用结构数组恶长
#include<stdioh>
struct stuScore
{
char name[20];
int number;
float math;
float comp;
};
void main()
{float sum1,sum2,sum3,sum4,sum5;
stuScore st1,st2,st3,st4,st5;
printf("请输入5位学生的学号、姓名、数学成绩、计算机成绩\n");
scanf("%d%s%f%f",&st1number,st1name,&st1math,&st1comp);
scanf("%d%s%f%f",&st2number,st2name,&st2math,&st2comp);
scanf("%d%s%f%f",&st3number,st3name,&st3math,&st3comp);
scanf("%d%s%f%f",&st4number,st4name,&st4math,&st4comp);
scanf("%d%s%f%f",&st5number,st5name,&st5math,&st5comp);
sum1=st1math+st1comp;
sum2=st2math+st2comp;
sum3=st3math+st3comp;
sum4=st4math+st4comp;
sum5=st5math+st5comp;
printf("学号\t姓名\t数学\t计算机\t总分\n");
printf("%4d\t %s\t %62f\t %62f\t %62f\n",st1number,st1name,st1math,st1comp,sum1);
printf("%4d\t %s\t %62f\t %62f\t %62f\n",st2number,st2name,st2math,st2comp,sum2);
printf("%4d\t %s\t %62f\t %62f\t %62f\n",st3number,st3name,st3math,st3comp,sum3);
printf("%4d\t %s\t %62f\t %62f\t %62f\n",st4number,st4name,st4math,st4comp,sum4);
printf("%4d\t %s\t %62f\t %62f\t %62f\n",st5number,st5name,st5math,st5comp,sum5);
}
#define Size 64
#include<stdioh>
int main()
{
char buf[Size],fn1[]="poem1txt",fn2[]="poem2txt";
FILE f1=NULL,f2=NULL;
f1=fopen(fn1,"r");
f2=fopen(fn2,"w+");
while(fgets(buf,Size,f1))
{
fputs(buf,f2);
}
fseek(f2,0,SEEK_SET);
while(fgets(buf,Size,f2))
{
printf("%s",buf);
}
fclose(f1);
fclose(f2);
return 0;
}
以上就是关于《C语言程序设计》实验报告全部的内容,包括:《C语言程序设计》实验报告、C语言程序设计,实验报告、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)