Saturday, March 8, 2014

To arrange the entered words in ascending order using string


By on 3:29 AM

In the last page I have made the pattern of string. Now lets move forward. In this page I have made the program to find the ascending order of the words entered by the user. For this I have taken two standard library functions called strcmp and strcpy. For more idea have a look for the source code and the program below:
The source code for the above output is:


#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char name[100][100],help[20];
int i,j,n;
printf("how many words\n");
scanf("%d",&n);
printf("enter all the words\n");
for(i=0;i<=n;i++)
{
gets(name[i]);
}
for(i=0;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(strcmp(name[i],name[j])>0)
{
strcpy(help,name[i]);
strcpy(name[i],name[j]);
strcpy(name[j],help);
}
}
}
printf("the words in ascending order is:");
for(i=0;i<=n;i++)
{
puts(name[i]);
}
getch();
}

About Authors

Aakash and Shreeram are owners of this website. Both are engineering student. Aakash is studying computer engineering and has passion with blogs and love to play with it while Shreeram is studying civil engineering and has dream of implementing technology in practical life.

0 comments :

Post a Comment