在上一题的基础上,编写一个函数input,用来输入5个学生的数据记录
答案:1 悬赏:40
解决时间 2021-02-17 15:32
- 提问者网友:不爱我么
- 2021-02-16 23:03
在上一题的基础上,编写一个函数input,用来输入5个学生的数据记录
最佳答案
- 二级知识专家网友:不想翻身的咸鱼
- 2021-02-17 00:29
#include
#include
#include
typedef struct Info
{
int num;
char name[21];
float score[3];
}DATA;
void print(DATA *SInfo,int n)
{
int i;
printf("%-4s%-21s%8s%8s%8s\n","num","name","score1","score2","score3");
for(i=0;i {
printf("%-4d%-21s%8.1f%8.1f%8.1f\n",SInfo[i].num,SInfo[i].name,SInfo[i].score[0],SInfo[i].score[1],SInfo[i].score[2]);
}
}
void input(DATA *SInfo)
{
int i;
printf("Please Input 5 student Info !\n");
for(i=0;i<5;i++)
{
printf("Please Input the %d student Info:",i+1);
printf("\nPlease Input the num:");
scanf("%d",&SInfo[i].num);
fflush(stdin);
printf("Please Input the name:");
scanf("%s",SInfo[i].name);
fflush(stdin);
printf("Please Input the score:");
scanf("%f%f%f",&SInfo[i].score[0],&SInfo[i].score[1],&SInfo[i].score[2]);
fflush(stdin);
}
}
void main()
{
DATA StuInfo[5];
int n;
input(StuInfo);
n=sizeof(StuInfo)/sizeof(DATA);
while(StuInfo[n].name[0]!='\0')
{
n++;
}
print(StuInfo,n);
getch();
}
#include
#include
typedef struct Info
{
int num;
char name[21];
float score[3];
}DATA;
void print(DATA *SInfo,int n)
{
int i;
printf("%-4s%-21s%8s%8s%8s\n","num","name","score1","score2","score3");
for(i=0;i
printf("%-4d%-21s%8.1f%8.1f%8.1f\n",SInfo[i].num,SInfo[i].name,SInfo[i].score[0],SInfo[i].score[1],SInfo[i].score[2]);
}
}
void input(DATA *SInfo)
{
int i;
printf("Please Input 5 student Info !\n");
for(i=0;i<5;i++)
{
printf("Please Input the %d student Info:",i+1);
printf("\nPlease Input the num:");
scanf("%d",&SInfo[i].num);
fflush(stdin);
printf("Please Input the name:");
scanf("%s",SInfo[i].name);
fflush(stdin);
printf("Please Input the score:");
scanf("%f%f%f",&SInfo[i].score[0],&SInfo[i].score[1],&SInfo[i].score[2]);
fflush(stdin);
}
}
void main()
{
DATA StuInfo[5];
int n;
input(StuInfo);
n=sizeof(StuInfo)/sizeof(DATA);
while(StuInfo[n].name[0]!='\0')
{
n++;
}
print(StuInfo,n);
getch();
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯