Write a C program that sorts a given array of names
#include<stdio.h>
#include<string.h>
void main()
{
int i,j,count;
char str[25][25],temp[25];
//clrscr();
printf("\n How many strings u are going to enter?: \n ");
scanf("%d",&count);
printf("\n Enter Strings one by one:\n ");
for(i=0;i<=count;i++)
gets(str[i]);
for(i=0;i<=count;i++)
for(j=i+1;j<=count;j++)
{
if(strcmp(str[i],str[j])>0)
{
strcpy(temp,str[i]);
strcpy(str[i],str[j]);
strcpy(str[j],temp);
}
}
printf("\n Order of Sorted Strings:\n ");
for(i=0;i<=count;i++)
puts(str[i]);
getch();
}
OUTPUT:
How many strings u are going to enter?:
6
Enter Strings one by one:
YAK
BROWNEE
ZEEBRA
APPLE
DUCKLING
PATRIC
Order of Sorted Strings:
APPLE
BROWNEE
DUCKLING
PATRIC
YAK
ZEEBRA
Comments
Post a Comment