/* PROGRAM TO PRINT LIST OF STRINGS IN SORTED ORDER */
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char s1[100][50],temp[50];
int i,j,n;
clrscr();
printf("\nEnter How Many Strings=");
scanf("%d",&n);
printf("\nEnter %d Strings=\n",n);
for(i=0;i<n;i++)
{
fflush(stdin);
gets(s1[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<=n-1;j++)
{
if((strcmp(s1[i],s1[j]))>0)
{
strcpy(temp,s1[i]);
strcpy(s1[i],s1[j]);
strcpy(s1[j],temp);
}
}
}
printf("\n After sorting the strings are=\n");
for(i=0;i<n;i++)
puts(s1[i]);
getch();
}
No comments:
Post a Comment