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:

























SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

4 comments: