diff --git a/step_6_update.c b/step_6_update.c new file mode 100644 index 0000000..d57454e --- /dev/null +++ b/step_6_update.c @@ -0,0 +1,86 @@ +#include +#include +#include +#define NAME 20 +#define SIZE 3 +struct student +{ + int id; + int class; + char name[NAME]; + float score_math; + float score_phi; + float score_eng; + bool ismodified; +}; + + +void update(struct student a[],int count){ + struct student temp; + scanf("%d %d %s %f %f %f",&temp.id,&temp.class,&temp.name,&temp.score_math,&temp.score_phi,&temp.score_eng); + for(int i = 0;i a[j+1].class){ + temp = a[j]; + a[j] = a[j+1]; + a[j+1] = temp; + } + } + } + for (int m = 0; m < count-1; m++) { + for (int n = m + 1; n < count-1; n++) { + if (a[n].class == a[n+1].class) { + float sum1 = a[n].score_math + a[n].score_phi + a[n].score_eng; + float sum2 = a[n+1].score_math + a[n+1].score_phi + a[n+1].score_eng; + if (sum1 < sum2 || (sum1 == sum2 && a[m].id > a[n].id)) { + struct student temp = a[n]; + a[n] = a[n+1]; + a[n+1] = temp; + } + } + } +} +} +void printgrade(struct student a[],int count){ + for(int i = 0;i