【学校作业】学生数据打印

数据结构课程布置了一门c语言的结构体作业
要求:
五个学生,数据包括学号,姓名,3门课的成绩,从键盘输入5个学生的数据。打印出3门课总平均成绩,以及最高分
强迫症患者表示打印出的数据必须美观,
必须有表格的形式,牌面还是要有的
所以有

在这里插入图片描述
下面贴出代码:

#include "stdio.h"
#include <stdlib.h>
#define SIZE 5 

struct student{
 char id[20];
 char name[20];
 int score[3];
} stud[SIZE];
float ave[SIZE];


void input() /* 输入学生的信息,学号、姓名,语文、数学、英语成绩 */
{
 int i;
 
 for(i=0;i<SIZE;i++)
 { 
 printf("第%d个学生的信息:(键入回车键表示一个信息的结束)\n",i+1);
 printf("请输入第%d个学生的学号:",i+1);
 scanf("%s",&stud[i].id); 
 printf("请输入第%d个学生的姓名:",i+1);
 scanf("%s",&stud[i].name); 
 printf("请输入第%d个学生的语文成绩:",i+1);
 scanf("%d",&stud[i].score[0]); 
 printf("请输入第%d个学生的数学成绩:",i+1);
 scanf("%d",&stud[i].score[1]); 
 printf("请输入第%d个学生的英语成绩:",i+1);
 scanf("%d",&stud[i].score[2]); 
// scanf("%s%s%d%d%d",stud[i].id,stud[i].name,&stud[i].score[0],&stud[i].score[1],&stud[i].score[2]);
 } 
}


void average() /* 求每个学生的总平均分 */
{
 int i;
 
 for(i=0;i<SIZE;i++)
 { 
 ave[i]=(stud[i].score[0]+stud[i].score[1]+stud[i].score[2])/3.0;
 } 
}


void max() /* 找出总分最高学生的数据 */
{
int i,j;
float ftemp;
 struct student temp;
 
 for(i=0;i<SIZE;i++)
 {
 for(j=0;j<SIZE-i-1;j++)
 {
 if(ave[j]<ave[j+1])
 {
 temp=stud[j];
 stud[j]=stud[j+1];
 stud[j+1]=temp;
 ftemp=ave[j];
 ave[j]=ave[j+1];
 ave[j+1]=ftemp;
 }
 } 
 }
 printf("\n最高分学生的数据:\n"); 
 printf("%4s %10s %8d %8d %8d %8.1f\n",stud[0].id,stud[0].name,stud[0].score[0],stud[0].score[1],stud[0].score[2],ave[0]);
}




void output() /* 输出学生的信息 */
{
 int i;
 
 printf("\n");
 printf("%5s %10s %8s %8s %8s %8s\n","学号","姓名","语文","数学","英语","平均分");
 for(i=0;i<SIZE;i++)
 printf("%4s %10s %8d %8d %8d %8.1f\n",stud[i].id,stud[i].name,stud[i].score[0],stud[i].score[1],stud[i].score[2],ave[i]);
}

void main()
{
 input();
 average();
 output();
 max();
}

让我郁闷的是自己的dev c++可以运行
学校里的vc6+报了两个错,什么float定义变量错误
两个编译器不一样啊,回头再看看啦。。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值