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