C Program
#include <stdio.h>
// Student structure
struct student
{
char name[10];
float gpa;
};
// Driver code
int main()
{
// Students array
struct student s[5], temp;
int n=5, i, j;
// Reading each student details
printf("Enter 5 student details[ studentname gpa] line by line\n");
for(i=0; i<n; i++)
{
scanf("%s", s[i].name);
scanf("%f", &s[i].gpa);
}
// Sorting student in descending order with respect to their gpa
for(i=0; i<n; i++)
{
for(j=i+1; j<n; j++)
{
if(s[i].gpa < s[j].gpa)
{
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
}
}
printf("\nStudent details after sorting\n");
// Printing student details after sorting
for(i=0; i<n; i++)
{
printf("%s %.2f\n", s[i].name, s[i].gpa);
}
return 0;
}
Input/Output: 1
input Enter 5 student details studentname gpa] line by line all 3.8 veli 1.7 mehmet 4.0 aye 3.2 nurdan 2.6 Student details af
Input/Output: 2
< input Enter 5 student details studentname gpa] line by line alex 3.4 john 5 witch 3 trump 4 ram 2.2 Student details after s
Program execution
Run Debug Stop Share Save {} Beautify Language C main.c 1 2 #include <stdio.h> 3 // Student structure 4 struct student 5- 6 c