Follow Us

LightBlog

Breaking

Tuesday, February 28, 2017

WAP to sort the characters of a string.


 WAP to sort the characters of a string?


#include<stdio.h>
#include<conio.h>
int main()
{
  int i,k,n;
  char string[20][20],temp[20];
  puts("Enter the no. of string to be sorted");
  scanf("%d",&n);
  for(i=0;i<=n;i++)
      gets(string[i]);
  for(i=0;i<=n;i++)
      for(k=i+1;j<=n;k++)
{
           if(strcmp(string[i],string[k])>0)
{
               strcpy(temp,string[i]);
              strcpy(string[i],string[k]);
              strcpy(string[k],temp);
           }
      }
  printf("The sorted string\n");
  for(i=0;i<=n;i++)
      puts(string[i]);
  return 0;
}

No comments:

Post a Comment