From 779195a21bf1b6c41f4767c97411b217e8b51860 Mon Sep 17 00:00:00 2001 From: pvkyt5ngb Date: Fri, 10 Nov 2023 11:59:34 +0800 Subject: [PATCH] =?UTF-8?q?Add=20=E6=AD=A5=E9=AA=A4=E4=B8=89.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 步骤三.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 步骤三.c diff --git a/步骤三.c b/步骤三.c new file mode 100644 index 0000000..32c9d35 --- /dev/null +++ b/步骤三.c @@ -0,0 +1,68 @@ +#include +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; +}