Create a program using C languge please ....... thanks The user will first input
ID: 3673393 • Letter: C
Question
Create a program using C languge please ....... thanks
The user will first input the number of students(less than 100). Then input the detailed information for each students including ID, name (less than 20 characters and do not contain spaces), grade for math and physics. Define a structure type and use a structure array to store the data input by the user. Use the qsort function in header file stdlib.h to sort the structure array. Then output the sorted array on the screen. Do not write your own code for sorting. The comparison standard is as follows. The student with greater total grade will rank first. If two students have the same total grade, the student with lower difference between the student's own grade for math and physics will rank first. If two students have the same total grade and the same grade difference, the student with less student ID will rank first. 4 101 Bob 80 90 125 Tom 81 91 133 Jim 82 90 131 Lucy 82 90 4 131 Lucy 82 90 133 Jim 82 90 125 Tom 81 91 101 Bob 80 90Explanation / Answer
I am not presenting the sorting function because without writing our code I did not find any predefined function to sort !!!
#include <stdio.h>
#include <stdlib.h>
struct student
{
char name[20];
int id;
int mathgrades;
int phygrades;
};
int main()
{
int n,i;
struct student s[100];
printf("enter number of students ");
scanf("%d",&n);
for(i=0;i<n;i++){
printf("enter student ID ");
scanf("%d",&s[i].id);
printf("enter student name ");
scanf("%s",&s[i].name);
printf("enter student math Grades ");
scanf("%d",&s[i].mathgrades);
printf("enter student physics grades ");
scanf("%d",&s[i].phygrades);
}
qsort(s,n,sizeof(s),);
printf("After sorting student details are ");
for(i=0;i<n;i++){
printf("%d %s %d %d ",s[i].id,s[i].name,s[i].mathgrades,s[i].phygrades);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.