u

Friday 14 September 2012

C++ Program to sort the given strings in Ascending order

C++ Program to sort the given strings in Ascending order

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
clrscr();
char name[10][20],temp[10][20];
int i,j,n;
printf ("\nENTER THE NUMBER OF NAMES TO BE ASCENDED : ");
scanf ("%d",&n);
for (i=0;i<n;i++)
{
printf ("ENTER THE %d NAME : ",i+1);
scanf ("%s",name[i]);
}
printf ("\n The ascending order of the names is : \n ");
for (i=0;i<n;i++)
{
for (j=i+1;j<n;j++)
{
if (strcmp(name[i],name[j])>0)
{
strcpy (temp[i],name[i]);
strcpy (name[i],name[j]);
strcpy (name[j],temp[i]);
}
}
printf ("\n%s",name[i]);
}
getch();
}

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More