You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.5 KiB
69 lines
2.5 KiB
#include <stdio.h>
|
|
int main() {
|
|
char choice;
|
|
int student_id[3];
|
|
float math_score[3], physics_score[3], english_score[3], total_score[3], average_score[3];
|
|
|
|
printf(" 1.Input\n");
|
|
printf(" 2.Output\n");
|
|
printf(" 3.Order\n");
|
|
printf(" 4.Quit\n");
|
|
printf("Please enter your choice: ");
|
|
scanf(" %c", &choice);
|
|
|
|
switch (choice) {
|
|
case 'i':
|
|
printf("Please input info of the three students:\n");
|
|
for (int i = 0; i < 3; i++) {
|
|
printf("Enter student %d's ID: ", i + 1);
|
|
scanf("%d", &student_id[i]);
|
|
printf("Enter student %d's math score: ", i + 1);
|
|
scanf("%f", &math_score[i]);
|
|
printf("Enter student %d's physics score: ", i + 1);
|
|
scanf("%f", &physics_score[i]);
|
|
printf("Enter student %d's english score: ", i + 1);
|
|
scanf("%f", &english_score[i]);
|
|
total_score[i] = math_score[i] + physics_score[i] + english_score[i];
|
|
average_score[i] = total_score[i] / 3;
|
|
}
|
|
|
|
// Sort by total score
|
|
for (int i = 0; i < 2; i++) {
|
|
for (int j = 0; j < 2 - i; j++) {
|
|
if (total_score[j] > total_score[j + 1]) {
|
|
// Swap total score
|
|
float temp_total = total_score[j];
|
|
total_score[j] = total_score[j + 1];
|
|
total_score[j + 1] = temp_total;
|
|
|
|
// Swap student ID
|
|
int temp_id = student_id[j];
|
|
student_id[j] = student_id[j + 1];
|
|
student_id[j + 1] = temp_id;
|
|
|
|
// Swap average score
|
|
float temp_average = average_score[j];
|
|
average_score[j] = average_score[j + 1];
|
|
average_score[j + 1] = temp_average;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Output sorted student information
|
|
for (int i = 0; i < 3; i++) {
|
|
printf("%d,%.1f,%.1f\n", student_id[i], total_score[i], average_score[i]);
|
|
}
|
|
break;
|
|
case 'm':
|
|
printf("You are trying to Make things ordered\n");
|
|
break;
|
|
case 'q':
|
|
printf("You are about to Quit\n");
|
|
break;
|
|
default:
|
|
printf("Wrong input\n");
|
|
}
|
|
|
|
return 0;
|
|
}
|