Question: Hello, my C program needs to to sort the array of students based on their total scores in descending order. Based on the code below

Hello, my C program needs to to sort the array of students based on their total scores in descending order. Based on the code below can you add a function that will do this? also when i try to compile it gives me a warning saying no newline detected at end of file. why is this?

#include #include #include #define MAX_SIZE1 20 #define MAX_SIZE2 10

typedef struct student { char name[MAX_SIZE1]; int score[MAX_SIZE2]; };

/*comparison function "comp()" start here*/ int comp(struct student *s1,struct student *s2) { if(sum(s1)>sum(s2)) return 1; /* if total score of s1 is greater than total score of s2 return 1 */ else return 0; }

int sum(struct student *s) /* it find the sum of grade */ { int i,su=0; for ( i=0;i<10;i++) su-su+s->score[1]; return su; } /* comparison function "comp()" end */

int main() { int n,i,j; time_t t; printf("Enter number of students: "); scanf("%d",&n); struct student s[n]; /*dynamic allocation of array*/

for(i=0; i { printf(" Enter the name of student:"); scanf("%s",s[i].name); srand((unsigned) time(&t)); for(j=0;j<10;j++) s[i].score[j]=50+rand()%50; }

/* output sorted result*/ printf("Name\t Subject1\t Subject2\t Subject3\t Subject4\t Subject5\t Subject6\t Subject7\t Subject8\t Subject9\t Subject10/t Total Score"); for(i=0;i { printf(" %s\t",s[i].name); for(j=0;j<10;j++) printf("%d\t",s[i].score[j]); printf("%d\t",sum(&s[i])); }

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!