Convert text into ascending order using string in C


This program is about convert and print the given string in ascending order using for loops.

Source Code

#include <stdio.h>
#include <string.h>
int main()
{
  char str[100],ch;
  int i,j,l;
  printf("Input the string : ");
  fgets(str, sizeof str, stdin);
  l=strlen(str);
  /* sorting process */
  for(i=1;i<l;i++)
  {
    for(j=0;j<l-i;j++)
	{
	  if(str[j]>str[j+1])
	  {
	    ch=str[j];
	    str[j] = str[j+1];
	    str[j+1]=ch;
	  }
	}
  }
   printf("Result : \n");
   printf("%s\n\n",str);
   return 0;
}
To download raw file Click Here

Output

Input the string : TUTORJOES
Result : EJOORSTTU


List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C


Learn All in Tamil © Designed & Developed By Tutor Joes