Program to sort the record of students merit wise in c language | C programs for practice

Write a program to sort the record of students merit wise in c language

In this post we are learning a program to sort the record of students merit wise in c language.

Program to sort the record of students merit wise in c language


Program to sort the record of students merit wise in c language:

#include <stdio.h> 
#include <conio.h>
struct student 
int rollno; 
char name [20];
char college [40]; 
int score; 
};
main () 
struct student s [20], temp; 
int n, i, j; 
printf("\n Enter the number of student: "); 
scanf("%d",&n); 
printf("\n Enter the Rollno, name, college-name and Score:"); 
for (i=0; i<n;++) 
scanf("%d%s%s %d", &s[i].rollno,s[i].name,s[i].college,&s[i].score); 
for (i=0;i<=n-1;i++) 
{
for (j=0; j <n-1;j++)
 if (s[j].score >s[j+1].score) 
{
temp =s[j]; 
s[j] = s[j+1]; 
s[j+1]= temp;
 }
}
}
 printf("\n The Merit list is \n"); 
for (j=0; j<n; j++)
 printf("%d %s%s%d",s[j].rollno,s[j].name,s[j].college,s[j].score); 
getch( ); 
}

Output: 

Enter the number of student: 3 
Enter the Rollno, name, college-name and Score 
122     Raj Kumar            D.A.V 222
123     Mohan Singh        Khalsa 238 
124     Rajan Hindu         200 
The Merit list is 
123     Mohan Singh        Khalsa 238 
122     Raj Kumar            D.A.V 222 
124     Rajan                    Hindu 200 
Previous
Next Post »

Please do not entering spam link in the comment box ConversionConversion EmoticonEmoticon