#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char name[20][15],t[20][15];
int i,j,n;
clrscr();
printf("\n Sorting the names in Alphabetical Order\n");
printf("\n *******************************\n");
printf("\n Enter the Number of Names \n");
scanf("%d",&n);
printf("\n Enter the Name one by one\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(t[i],name[i]);
strcpy(name[i],name[j]);
strcpy(name[j],t[i]);
}
}
}
printf("\n OUTPUT\n");
printf("\n Sorting the Names \n");
printf("\n****************\n");
for(i=0;i<n;i++)
{
printf("\n%s",name[i]);
}
getch();
}
#include<conio.h>
#include<string.h>
void main()
{
char name[20][15],t[20][15];
int i,j,n;
clrscr();
printf("\n Sorting the names in Alphabetical Order\n");
printf("\n *******************************\n");
printf("\n Enter the Number of Names \n");
scanf("%d",&n);
printf("\n Enter the Name one by one\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(t[i],name[i]);
strcpy(name[i],name[j]);
strcpy(name[j],t[i]);
}
}
}
printf("\n OUTPUT\n");
printf("\n Sorting the Names \n");
printf("\n****************\n");
for(i=0;i<n;i++)
{
printf("\n%s",name[i]);
}
getch();
}
0 comments:
Post a Comment