#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
struct Student{
int num;
char name[20];
float score;
int age;
}student1,student2;
//scanf("%d%s%f%d",&student1.num,student1.name,student1.score,student1.age);
scanf("%d%c%6.2f%d",&student1.num,&student1.name,&student1.score,&student1.age);
scanf("%d%c%f%d",&student2.num,&student2.name,&student2.score,&student2.age);
printf("The higher score is:\n");
if(student1.score > student2.score)
{
printf("%d %c %6.2f %d\n",student1.num,student1.name,student1.score,student1.age);
}
else if(student1.score < student2.score)
{
printf("%d %c %6.2f %d\n",student2.num,student2.name,student2.score,student2.age);
}
else
{
printf("%d %s %f %d\n",student1.num,student1.name,student1.score,student1.age);
printf("%d %c %6.2f %d\n",student2.num,student2.name,student2.score,student2.age);
}
return 0;
}
这个好像是错误的,我想用c语言,在已知数据的情况下,赋值,并且根据成绩打印,如何改动呢
scanf("%d%c%6.2f%d" 改为scanf("%d%s%f%d"
字符串输入用%s
结构体移到main()前面去