Business

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();
}

Show More

J. Satya

Started blogging in 2010 but working professionally from 2012. Apart from that working as a Digital Marketer, SEO & Conversion Specialist. Helping individuals as well as business to grow.

Related Articles

Leave a Reply

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

Back to top button
Close
Close