ProAnswers.org

Write a C program to perform the sorting the given Strings in Ascending Order ?

#include

#include 

#include 

void main() 

{ 

int i,j,n,x; 

char str[20][20],str1[20][20]; 

clrscr(); 

printf(“enter the number of strings:

”);

scanf(“%d”,&n); 

for(i=0;i

{ 

printf(“

enter str[%d]”,i+1);

scanf(“%s”,&str[i]); 

} 

for(i=0;i

{ 

for(j=i+1;j

{ 

x=strcmp(str[i],str[j]) 

if(x>0) 

{ 

strcpy(str[1],str[j]); 

strcpy(str[j],str[i]); 

strcpy(str[i],str[1]); 

} 

} 

} 

printf(“

the sorted strings in ascending order is
”);

for(i=0;i

{ 

printf(“

%s”,str[i]);

} 

getch(); 

} 

Output: 

enter the number of strings: 

3 

enter str[1] raja 

enter str[2] vignesh 

enter str[3] adhi 

the sorted strings in ascending order is 

adhi 

raja 

vignesh