QUESTION
In the company, there are some number of employees. Employee list was unordered. You have to prepare the list of the employee details depending upon year of entry.
ANSWER
#include <stdio.h>
struct emp{
char name[30];
int year;
};
int main()
{
struct emp e[10],temp;
int i,j,n;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s",e[i].name);
scanf("%d",&e[i].year);
}
for (i = 0; i < n; i++)
{
for (j = 0; j < (n-1-i); j++)
{
if (e[j].year > e[j + 1].year)
{
temp = e[j];
e[j] = e[j + 1];
e[j + 1] = temp;
}
}
}
printf("After sorting\n");
for(i=0;i<n;i++)
printf("%s %d\n",e[i].name,e[i].year);
return 0;
}