Categories




C program to arrange name in alphabetical order using string function

Hi
Today we will learn C program to arrange given name in alphabetical order using string function

Problem Discussion:

1) In program we create 2D array to store name .
2) Take name from user and store in name.
3) Using string compare function and copy function arrange name in alphabetical order.
4) Display result.

NOTE: If you are just beginner in programming or just have started learning C program then I recommended you to first visit following topics or course . So you can understand this programming clearly without miss-understanding. .

* Switch Case
* Array and Type’s
* Looping or Loop 
* String

So without delay let’s go to programming.

C Program To Arrange Name In Alphabetical Order Using String Function


 
 #include<stdio.h>  
#include<conio.h>
#include<string.h>
main()
{
 char name[100][100];
 int n,i,j;
 char temp[100];
 printf("n How many student");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  printf("n Enter name");
  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("n Arranging name in Alphabetical order..");
 for(i=0;i<n;i++)
 {
  printf("n %s",name[i]);
 }
 getch();
}

Explanation:

1) First we will take name string character to store name from user. Then ask user to enter how                many name he/she want to enter.
2) Take name from user and store that value in name 2D array .
3)¬† Using for loop we will repeat the statement as we want then ‘strcmp’ to compare name[i] and name[j] in two dimensional array.
4) Arrange name according to ascending order there we have use “strcpy” .
5) Finally print arranged name using “printf”.

OUTPUT:

 

Output.

So this is our output , I think you have understand programming . If not then you can simply got visit my social media page and comment your question .Or comment below in comment box I will available   hours for you.

 

 

 

 

 

 

 

 

 

SIMILAR POST:

C program to convert lowercase to upper case using string function.
Program to find the length of string.
Menu driven program to calculate area and perimeter of rectangle .
C program to print name of days of week using switch case.
C program to find smallest among three number.

Loading...

admin

One thought on “C program to arrange name in alphabetical order using string function

Leave a Reply

Your email address will not be published. Required fields are marked *