1)定义一个结构体描述学生信息(学号,姓名,性别,年龄,住址); 2)设计一个函数,用于显示单个学生信息,函

2024-11-17 23:50:22
推荐回答(1个)
回答1:

struct stu
{
long int Num;
char name[20];
char gender[10];
int age;
char addr[100];
};

void print_stu_mes(struct stu* pStu,int i)
{
printf("the %dth student's personal message is:\n",(i+1));
printf("Number is:%ld\nName is:%s\nGender is:%s\nAge is:%d\nAddress is:%s\n",pStu->Num,pStu->name,pStu->gender,pStu->age,pStu->addr);
}
void main()
{
struct stu student[5];
for(int i=0;i<5;i++)
{
printf("Input the %dth student's message\n",(i+1));
scanf("%ld %s %s %d %s",&student[i].Num,student[i].name,student[i].gender,&student[i].age,student[i].addr);
}
for(i=0;i<5;i++)
{
print_stu_mes(&student[i],i);
}
}