Monday 6 January 2014

C PROGRAM TO DEVELOP SORTING THE STRINGS IN ALPHABETICAL ORDER

#include<stdio.h>
#include<string.h>
#include<conio.h>


int main()
{
    char str[10][20];
    char temp[20];
    char ch;
    char *dest;
    int i=0,j=0,k=0;
  
  
    while(strlen(gets(str[i++]))!=0)
    ;
    i--;
  
    while(k<=i)
    {
    for(j=k;j<=i-1;j++)
    {
                    if((strcmp(str[k],str[j]))>0) //swap
                    {
                                                    strcpy(temp,str[j]);
                                                    strcpy(str[j],str[k]);
                                                    strcpy(str[k],temp);
                                                    }
                                                    }
                                                    k++;
                                                    }
                                                  
                                                  
for(j=0;j<=i;j++)
puts(str[j]);

getch();
return 0;
}                                                  

No comments:

Post a Comment