C Program to Input Students Name and Sort Alphabetical Order

C Program to Input the Names of N numbers of Students and Sort them in Alphabetical Order. C Program to Input Students Name and Sort Alphabetical Order

Write a C program to input the names of ‘n’ numbers of students and sort them in alphabetical order.
C Program to Input the Names of N numbers of Students and Sort them in Alphabetical Order. 
C Program to Input Students Name and Sort Alphabetical Order

Source Code


#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
 char name[30][25],temp[25];
 int i,j,n;
 clrscr();
 printf("Enter how many students");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  printf("\nEnter the name of the student:");
  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("The sorted names are:");
 for(i=0;i<n;i++)
 {
  printf("\n%s",name[i]);
 }
 getch();
}

You May Also Like...

Socialize with Us