QUESTION
You are given a word document in that there will be list of employees name will be unordered, you have to arrange the list of employee in the alphabetical order in the word document.
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 (strcmp(e[j].name,e[j + 1].name)>0)
{
temp = e[j];
e[j] = e[j + 1];
e[j + 1] = temp;
}
}
}
printf("After sorting\n");
printf("Name ID\n");
for(i=0;i<n;i++)
printf("%s %d\n",e[i].name,e[i].year);
return 0;
}