C程序设计(第五版)【谭浩强】第九章课后习题3
//成绩数组(num,name,score[3]),主函数输入,print函数输出
#include<stdio.h>
#define _CRT_SECURE_NO_WARNINGS
//定义结构体
struct student
{
int num;
char name[20];
float score[3];
};
//myprint函数
void myprint(struct student a[],int n)
{
for (int i = 0; i < n; i++)
{
printf("%2d %2s%7.2f%7.2f%7.2f\n", a[i].num, a[i].name, a[i].score[0], a[i].score[1], a[i].score[2]);
}
}
int main()
{
//定义结构体变量
struct student stu[5] = {
{122,"zhl",98,97,96},
{123,"cjw",96,95,56},
{124,"lcw",89,67,46},
{125,"zzc",12,14,16},
{126,"hgz",45,23,98}
}; //在主函数直接输入
试试键盘输入------键盘输入VS2019总是报错,烦死了
//printf("Please enter information of student:\n");
//struct student stu[5];
//for (int i = 0; i < 5; i++)
//{
// scanf_s("%d%s%f%f%f", &stu[i].num, stu[i].name, &stu[i].score[0], &stu[i].score[1], &stu[i].score[2]);
//}
//调用myprint函数输出
myprint(stu, 5);
return 0;
}