|
发表于 2020-7-19 20:00:02
|
显示全部楼层
#include <stdio.h>
struct person
{
char name[20];
char sex[3];
int age;
};
struct student
{
char number[10];
int score;
struct person roommate;
};
void main()
{
int i;
struct student myroommate[2];
printf("----------------¼Æ¿ÆϵÈý°à---------------------\n");
printf("ÇëÊäÈëÄãËÞÉá³ÉÔ±µÄѧºÅ¡¢³É¼¨¡¢ÐÕÃû¡¢ÐÔ±ð¡¢ÄêÁä:\n");
printf("-----------×¢ÒâÊäÈë¸÷¸ö²¿·ÖÒÔ','·Ö¿ª-----------\n");
for(i=0;i<2;i++)
{
printf("ѧºÅ:");
scanf("%s",myroommate[i].number);
printf("³É¼¨:");
scanf("%d",&myroommate[i].score);
printf("ÐÕÃû:");
scanf("%s",myroommate[i].roommate.name);
fflush(stdin);
printf("ÐÔ±ð:");
scanf("%s",myroommate[i].roommate.sex);
fflush(stdin);
printf("ÄêÁä:");
scanf("%d",&myroommate[i].roommate.age);
}
printf("ËÞÉá³ÉÔ±µÄѧºÅ¡¢³É¼¨¡¢ÐÕÃû¡¢ÐÔ±ð¡¢ÄêÁä·Ö±ðÊÇ:\n");
for(i=0;i<2;i++)
{
printf("ѧºÅ:%s, ³É¼¨:%d, ÐÕÃû:%s, ÐÔ±ð:%s, ³É¼¨:%d\n",
myroommate[i].number,
myroommate[i].score,
myroommate[i].roommate.name,
myroommate[i].roommate.sex,
myroommate[i].roommate.age);
}
} |
|