From 488d3e5f071243b79fbaf83009b0ac6fbf367c25 Mon Sep 17 00:00:00 2001 From: psc7qx9jf Date: Sun, 5 Nov 2023 12:44:03 +0800 Subject: [PATCH] ADD file via upload --- step_5(3).c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 step_5(3).c diff --git a/step_5(3).c b/step_5(3).c new file mode 100644 index 0000000..c06f174 --- /dev/null +++ b/step_5(3).c @@ -0,0 +1,67 @@ + +#include +#include + +struct student{ + char study[5]; + int grade; + char name[10]; + float gradeone; + float gradetwo; + float gradethree; +}; + +int main() +{ + struct student grade[3]; + strcpy(grade[0].study, "10001"); + grade[0].grade = 11; + strcpy(grade[0].name, "Liang"); + grade[0].gradeone = 99.5; + grade[0].gradetwo = 88.5; + grade[0].gradethree = 89.5; + + strcpy(grade[1].study, "10002"); + grade[1].grade = 12; + strcpy(grade[1].name, "Zhang"); + grade[1].gradeone = 77.9; + grade[1].gradetwo = 56.5; + grade[1].gradethree = 87.5; + + strcpy(grade[2].study, "10003"); + grade[2].grade = 11; + strcpy(grade[2].name, "Wang"); + grade[2].gradeone = 92.5; + grade[2].gradetwo = 99.0; + grade[2].gradethree = 60.5; + + char yonghu[10]; + scanf("%s", yonghu); + + int i; + for (i = 0; i < 3; i++) { + if(strcmp(yonghu, grade[i].study) == 0 || strcmp(yonghu, grade[i].name) == 0) + break; + } + + for(int j = 0; j < 3; j++){ + if(j != i) { + printf("%s %d %s %.1f %.1f %.1f\n", grade[j].study, grade[j].grade, grade[j].name, grade[j].gradeone, grade[j].gradetwo, grade[j].gradethree); + } else { + printf("%s %d %s %.1f %.1f %.1f\n", grade[j + 1].study, grade[j + 1].grade, grade[j + 1].name, grade[j + 1].gradeone, grade[j + 1].gradetwo, grade[j + 1].gradethree); + j=j+1; + } + } + + printf("Are you sure (Yes/No)?"); + char answer; + scanf(" %c", &answer); + + if(answer == 'N') { + for(int j = 0; j < 3; j++){ + printf("%s %d %s %.1f %.1f %.1f\n", grade[j].study, grade[j].grade, grade[j].name, grade[j].gradeone, grade[j].gradetwo, grade[j].gradethree); + } + } + + return 0; +} \ No newline at end of file