題目要求
輸入兩個學生的學號、姓名和成績,輸出成績較高學生的學號、姓名和成績。
思路分析
這題比較簡單,如果不會做,多看幾遍分析,自己多敲幾遍代碼
- 輸入兩個學生的信息,有學號,姓名,成績
- 比較成績(這裏就有3中情況,A的成績比B好,B的成績比A好,A的成績等於B的成績)
- 輸出成績比較之後的結果
代碼演示
#include<stdio.h>
struct student
{
int id;
char name[20];
double f;
} stu1,stu2;
int main()
{
printf("請輸入學生1的信息:\n");
scanf("%ld %s %lf",&stu1.id,stu1.name,&stu1.f);
printf("請輸入學生2的信息:\n");
scanf("%ld %s %lf",&stu2.id,stu2.name,&stu2.f);
if(stu1.f>stu2.f)
{
printf("比較優秀的學生是%s,學號是%ld,分數是%5.2f",stu1.name,stu1.id,stu1.f);
}
else if(stu1.f<stu2.f)
{
printf("比較優秀的學生是%s,學號是%ld,分數是%5.2f",stu2.name,stu2.id,stu2.f);
}
else
{
printf("這些學生都非常優秀!");
}
return 0;
}