HSEB-2066(2.a)

//2066
//Q.2.a.Write a Program to store name and mark o 20 students. Sort the data according with mark in descending order and display them.
#include<stdio.h>
#define n 20
struct student
{
char name[20];
int mark;
};
void main()
{
struct student S[n],temp;
int i,j;
printf("enter the name and marks of 20 students:");
for(i=0;i<n;i++)
{
scanf("%s%d",S[i].name,&S[i].mark);
}


for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(S[i].mark>S[j].mark)
{
temp=S[i];
S[i]=S[j];
S[j]=temp;
}
}
}
printf("\nName \tMark");
for(i=0;i<n;i++)
{
printf("\n%s \t%d",S[i].name,S[i].mark);
}
printf("\n<....................>");
}

Leave a Reply

Your email address will not be published.