Welcome to my blog this is test

28 June 2012

write a C program to SORT A STRING IN ALPHABETICAL ORDER


//Code:
#include
#include
#include
 void main()
  {
   char a[20],b[20];
   int i,j,n,temp;
   clrscr();
   printf("\n Enter any string : ");
   gets(a);
   n=strlen(a);
   for(i=0;i
    {
     for(j=0;j
      {
       if(a[j]>a[j+1])
          {
           temp=a[j];
           a[j]=a[j+1];
           a[j+1]=temp;
          }}}
          printf("\n The final string is :");
    for(i=0;i<=n;i++)
    printf("%c",a[i]);
   getch();
  }

/*Output:
Enter any string : baaba
The final string is : aaabb

No comments:

Post a Comment