source file name: sortstrings.C
#include <string.h>
#include <stdio.h>
int main()
{
char temp[10];
int i,j,n;
char names[10][10]={"Raju","Harish","Kailas","Arun,","Satish",
"Jayvant","Rajendra","Suresh","Prashant","Nivas"};
//clrscr();
printf(" given students names: \n ");
for(i=0;i<10;i++)
{
printf("%s ",names[i]);
}
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
n=strcmp(names[i],names[j]);
if(n<0)
{
strcpy(temp,names[i]);
strcpy(names[i],names[j]);
strcpy(names[j],temp);
}
}
}
printf("\n sorting students names: \n ");
for(i=0;i<10;i++)
{
printf("%s ",names[i]);
}
//getch();
return 0;
}
output:
0 Comments
Post a Comment