#include<stdio.h>
#include<string.h>
struct student
{
char name [25];
int mark;
}std[10];
void main()
{
char temp[25];
int i,j,tm;
printf("Enter names and marks for 20 students\n");
for(i=0;i<20;i++)
{
scanf("%s",std[i].name);
scanf("%d",&std[i].mark);
}
for(i=0;i<20;i++)
{
for(j=i+1;j<20;j++)
{
if(std[i].mark<std[j].mark)
{
tm=std[i].mark;
std[i].mark=std[j].mark;
std[j].mark=tm;
strcpy(temp,std[i].name);
strcpy(std[i].name,std[j].name);
strcpy(std[j].name,temp);
}
}
}
printf("\nThe sorted names and marks in descending order according to marks are\n");
for(i=0;i<20;i++)
printf("\n%s\t%d",std[i].name,std[i].mark);
getch();
}
No comments:
Post a Comment
Rahul-Notes