program to sort the N names in alphabetical order - My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Friday, January 17, 2020

program to sort the N names in alphabetical order - My CS Tutorial

C program to sort the string in alphabetical order.
In this tutorial we will learn how to write a c program that print the sort order of names.


C program code


#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,j,n;
char str[100][100],s[100];
printf("\n ENTER NUMBER OF NAMES OR STRING:\n ");
scanf("%d",&n);
printf("\n ENTER NAMES OR STRING:\n ");
for(i=0;i<n;i++)
{
 scanf("%s",str[i]);
}


for(i=0;i<n;i++)
{
 for(j=i+1;j<n;j++)
 {
   if(strcmp(str[i],str[j])>0)
   {
    strcpy(s,str[i]);
    strcpy(str[i],str[j]);
    strcpy(str[j],s);
   }

 }

}
printf("\n THE SORTED ORDER OF NAMES OR ALPHABATES ARE:\n ");
for(i=0;i<n;i++)
{
 printf("%s\n",str[i]);
}
getch();
}


OUTPUT:




In the first we will enter the numbers or range of names then we will enter the names.

Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com

Created by-- HARSH CHAUHAN



No comments:

Post a Comment