Enter name and arrange in alphabetical order in C-Programming

#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char name[5][10],temp[10];
int i,j;
for(i=0;i<5;i++)
{
printf("input the name of student:");
scanf("%s",name[i]);
}
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(strcmp(name[i],name[j])>0)
{
strcpy(temp,name[i]);
strcpy(name[i],name[j]);
strcpy(name[j],temp);
}
}
}
printf("\n NAme in alphabetical order\n");
for(i=0;i<5;i++)
{
printf("%s\t",name[i]);
}
}

Leave a Reply

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

Enter Captcha Here : *

Reload Image