diff --git a/step_4_insert.c b/step_4_insert.c new file mode 100644 index 0000000..ba08be5 --- /dev/null +++ b/step_4_insert.c @@ -0,0 +1,83 @@ +#include +#include + +struct student +{ + int id; + int class; + float score_math; + float score_phi; + float score_eng; + bool isinserted; +}; + + + void sort(struct student a[],int count){ + struct student temp; + for(int i = 0;i < count-1;i++){ + for(int j = i+1;j 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