Requirement: write a program to enter the student's student ID, name, and score information, sorted from high to low according to the student's score.
# Include <stdio. h>
# Include <string. h>
Typedef struct student_score
{
Int ID;
Char name [20];
Int score;
} Stu; // defines the struct.
Int main (INT argc, const char * argv [])
{
Int I, J;
Int num;
Stu TMP, STU [100];
Printf ("how many students? Input the num :");
Scanf ("% d", & num); // enter the number of students
for (I = 0; I {< br> printf ("plz input the [num: % d] Student's ID: \ n ", I + 1);
scanf (" % d ", & STU [I]. ID);
puts ("plz input the name:");
scanf ("% s", STU [I]. name);
puts ("plz input the score:");
scanf ("% d", & STU [I]. score);
}< br>/*
to prevent incorrect input, use:
int ret;
ret = scanf ("% d % S % d", & STU [I]. ID, STU [I]. name, STU [I]. score);
If (Ret! = 3)
printf ("input error");
*/
printf ("=================================\ N ");
printf ("| ID name Score \ n");
for (I = 0; I {< br> printf ("| % d % S % d \ n", STU [I]. ID, STU [I]. name, STU [I]. score);
}< br> for (I = 0; I for (j = 0; j {// if the number of students is 3, the comparison is only twice. So the cycle condition: j
If (STU [J]. score <STU [J + 1]. Score)
{
TMP = STU [J];
STU [J] = STU [J + 1];
STU [J + 1] = TMP;
}
}
Printf ("=================================\ N ");
For (I = 0; I <num; I ++)
{
Printf ("| % d % S % d \ n", STU [I]. ID, STU [I]. Name, STU [I]. Score );
}
Return 0;
}