We provide Engineering,HSEB notes, tutorials which can be helpful for students during college life.
Friday, April 10, 2015
11. Write a C program to input names of 'n' numbers of students and sort them in alphabetical order.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main() {
int i,j,n;
char name[100][100],temp[100];
clrscr();
printf("\n How many students:- ");
scanf("%d",&n);
printf("\n Input name of %d students",n);
for(i=0;i<n;i++)
{
fflush(stdin);
printf("\n Name [%d]:- ",i+1);
gets(name[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(strcmp(temp,(name[i],name[j]>0)
{
strcpy(temp,name[i]);
strcpy(name[i],name[j]);
strcpy(name[j],temp);
}
}
}
printf("\n Name in alphabetical order are:\n");
for(i=0;i<n;i++)
printf("\n %s", name[i]);
getch();
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment