Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Sort given string in ascending order

Posted By: Luki Fischer     Category: C Programming     Views: 21923

Sort given string in ascending order.

Code for Sort given string in ascending order in C Programming

#include<stdio.h>
#include<conio.h>

int main()
{
    char str[100],temp;
    int i,j;
    clrscr();
    printf("Enter the string :");
    gets(str);
    printf("%s in ascending order is -> ",str);
    for(i=0;str[i];i++)
    {
        for(j=i+1;str[j];j++)
        {
            if(str[j]<str[i])
            {
                temp=str[j];
                str[j]=str[i];
                str[i]=temp;
            }
        }
    }
    printf("%s\n",str);
    getch();
    return 0;
}




Output:

Enter the string : syntax
syntax in ascending order is -> anstxy
  
Share: 


Didn't find what you were looking for? Find more on Sort given string in ascending order Or get search suggestion and latest updates.

Luki Fischer
Luki Fischer author of Sort given string in ascending order is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!