如果用gets则无法输入八组数据 如果换为scanf则可以输入8组数据这是为啥呢
#include <stdio.h>#include <string.h>
int main(void)
{
float sum,ave;
int i;
struct student
{
int num;
char name;
char sex;
int admissiontime;
float computer;
float english;
float math;
float program;
char zp;
}stu1;
scanf("%d",&stu1.num);
gets(stu1.name);
gets(stu1.sex);
scanf("%d",&stu1.admissiontime);
scanf("%f",&stu1.computer);
scanf("%f",&stu1.english);
scanf("%f",&stu1.math);
scanf("%f",&stu1.program);
sum=stu1.computer+stu1.english+stu1.math+stu1.program;
ave=sum/4;
if(ave>=90)
strcpy(stu1.zp,"优");
else if(ave>=60)
strcpy(stu1.zp,"合格");
else
strcpy(stu1.zp,"不合格");;
printf("%s",stu1.zp);
return 0;
}
gets能读入空格,可能和你输入方式有关系。了解一下gets和scanf的区别
页:
[1]