Advertisement
Shailrshah

String Sorting

Apr 18th, 2013
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. int main()
  3. {
  4.     char str[100],temp;
  5.     int l,i,j;
  6.     printf("Enter a string.\n");
  7.     fgets(str,sizeof(str),stdin);
  8.     for(l=0;str[l]!='\0';l++)
  9.     {}
  10.     printf("\nIt has %d characters.\n",l-1);
  11.     for (i = 0; i <(l-2); i++)
  12.     {
  13.         for (j = 0; j <(l-i-2); j++)
  14.         {
  15.             if (str[j] > str[j+1])
  16.              {
  17.                 temp = str[j];
  18.                 str[j] = str[j+1];
  19.                 str[j+1] = temp;
  20.             }
  21.         }
  22.     }
  23.         printf("\nArranging alphabetically, we get %s.",str);
  24.     return 0;
  25. }
  26. //Output
  27. //Enter a string.
  28. //programming
  29.  
  30. //It has 11 characters.
  31.  
  32. //Arranging alphabetically, we get aggimmnoprr.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement