c语言怎么实现???在线等

来源:百度知道 编辑:UC知道 时间:2024/06/08 02:19:30
(2) 使用printf函数,输出以下结果:
姓名 学号 成绩1 成绩2 总分
张三 2001 79.0 81.5 ?
李四 2002 85.0 97.5 ?
王二 2003 95.0 54.0 ?
注:?为具体的总分值。
要求输出表格的形式

#include<stdio.h>

#define MAX 100 //学生数目,可以修改

struct student
{
char name[20];
long num;
float score[2];
float scoreall;
};

void main()
{
int count,i;
struct student stu[MAX];
printf("请输入学生数!\n");
scanf("%d",&count);
printf("请分别输入学生的姓名、学号、成绩1、成绩2,以空格隔开。否则后果自负!\n");
for (i = 0; i < count;i++)
{
scanf("%s%d%f%f",&stu[i].name,&stu[i].num,&stu[i].score[0],&stu[i].score[1]);
stu[i].scoreall = stu[i].score[0] + stu[i].score[1];
}
printf("姓名\t学号\t成绩1\t成绩2\t总分\n");
for(i=0;i<count;i++)
{
printf("%-8s%-8d%-8.2f%-8.2f%-8f",stu[i].name,stu[i].num,stu[i].score[0],stu[i].score[1],stu[i].scoreall);
printf("\n");
}
}

已经验证。

1.
用指针变量输出结构数组。
struct stu
{
int num;