Tuesday, April 7, 2015

51 .Write a program which reads name of 20 employees and sort them in alphabetical order.

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i, j, n;
char name[20][30],temp[30];
clrscr();
printf("\n Input name of 20 students"); 

for(i=0;i<20;i++) 
{
fflush(Stdin);
printf("\n Name [%d]:- ",i+l);
gets(name[i]); '
}
for{i=0;i<n-1;i++}
{
for(j=i+l;j<n;j++)
{
if(strcmp(name[i],name[j])>O)

{
Strcpy(temp,name[i]);
Strcpy(name[i],name[j]);
Strcpy(name[j],temp);

    }
  }

}
printf("\n Name in Alphabetical order are: \n");
for(i=0;i<20;i++)

printf("\n %s", name[i]);
getch();
}


No comments:

Post a Comment