Display Strings in alphabetical order

/****   PROGRAM Read n values (string) from keyboard
    display string list in alphabetical order  ****/
#include<conio.h>
#include<stdio.h>
#include<string.h>

int main()
   {
     int i,j,n;
     char s[20][20],t[20];
     printf(HOW MANY COUNTRIES: );
     scanf("%d",&n);
     printf(" ENTER ANY %d COUNTRY NAME \n",n);
for(i=0;i<n;i++)
{
   scanf("%s",s[i]);
}
for(i=0;i<n-1;i++)
{
     for(j=i+1;j<n;j++)
     {
        if(strcmp(s[i],s[j])>0)
        {
           strcpy(t,s[i]);
           strcpy(s[i],s[j]);
           strcpy(s[j],t);
        }
     }
 }
     printf("\n THE ALPHABATICAL LIST IS \n");
     for(i=0;i<n;i++)
       printf("%s\n",s[i]);
     getch();
   }


OUTPUT:






























Comments

Popular posts from this blog

Program for find average of five numbers

program for sorting array using selection sort technique || in c programming language

Program to calculate the sum of given number using array