C Program – Sorting of a Set of Strings in Ascending alphabetical order.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,j,n;
char name[50][50],temp[50];
printf("How many names you want to enter bro?: ");
scanf("%d",&n);
printf("Enter names one by one: ");
for(i=0;i<n;i++)
{
scanf("%s",name[i]);
}
for(i=0;i<n;i++)
{ for(j=i+1;j<n;j++)
{
if(strcmp(name[i],name[j])>0)
{ strcpy(temp,name[i]);
strcpy(name[i],name[j]);
strcpy(name[j],temp);
}
}
}
printf("Order of Sorted names:\n");
for(i=0;i<n;i++)
{
printf("%s",name[i]);
}
getch();
}
OUTPUT:
wow !...thanks for copyable code.
ReplyDeletewow!.. thanks for copyable code ;
ReplyDeleteno problem bro !
Deletethank for help
ReplyDelete