Categories




Program to arrange given name in descending order using string function.

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

Problem Discussion:

1) In the program, we create a 2D array to store name.
2) Take a name from user and store in the name.
3) Using string compare function and copy function arrange name in descending 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 Given Name In Descending 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 descending order there we have use “strcpy” .
5) Finally print arranged name using “printf”.

OUTPUT:


















So that it, If you have any problem then you can comment below or visit my social media page and leave your comment . I will be available 24 hours for you.

SIMILAR POST:

C program to arrange given name in ascending order using string function.
Program to fin the length of string.
C program to reverse string using string function.
C program to read salary of 200 employee and count number of employee getting salary between 5000 to 10,000
C program to  enter ‘n’ number and find largest and smallest .

Loading...

admin

Leave a Reply

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

error: Content is protected !!