Jan
24
#include<stdio.h>
#include<conio.h>
void main(){
int i,k,n;
char name[50][30],temp[30];
clrscr();
printf(“Enter number of persons: “);
scanf(“%d”,&n);
printf(“\n”);
fflush(stdin);
for(i=0;i<n;i++){
printf(“Enter name of person %d: “,i+1);
gets(name[i]);
}
for(k=0;k<n-1;k++){
for(i=0;i<n-k-1;i++){
if(strcmp(name[i],name[i+1])>0){
strcpy(temp,name[i]);
strcpy(name[i],name[i+1]);
strcpy(name[i+1],temp);
}
}
}
printf(“\nSorted list…\n\n”);
for(i=0;i<n;i++)
puts(name[i]);
getch();
}
Leave a Reply
No Comments