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;
}
这篇博客展示了如何使用C语言定义结构体数组,包含学生信息(编号、姓名和三门成绩),并定义了一个`myprint`函数用于输出数组中的学生信息。在主函数中直接初始化了学生数组,并调用`myprint`进行打印。虽然尝试了键盘输入学生信息,但由于编译器问题未能实现。
【谭浩强】第九章课后习题3&spm=1001.2101.3001.5002&articleId=120310426&d=1&t=3&u=1b0d99655da44db98272db01631dd1ee)
417

被折叠的 条评论
为什么被折叠?



