Program to sort input names in alphabetically ascending order by using C programming
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
int i,j,n;
printf("enter how many students you want to enter:\n");
scanf("%d",&n);
char name[n][30], temp[30];
printf("enter %d name of student:\n",n);
for(i=0;i<n;i++)
{
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\nThe sorted name are:");
for(i=0;i<n;i++)
{
printf("\n%s",name[i]);
}
getch();
}
No comments:
Post a Comment