Friday, November 23, 2012

WRITE A C PROGRAM TO ARRANGE ALL CHARACTERS IN A STRING IN ASCENDING ORDER.


/*  WRITE A C PROGRAM TO ARRANGE ALL CHARACTERS IN A STRING
    IN ASCENDING ORDER.
*/

#include<stdio.h>
#include<conio.h>
#define MAX 30

void main()
{
            char str[MAX],*fr,*re,temp;
            int i,j;
            clrscr();
            printf("\n Enter a String : ");
            gets(str);
            for(fr=str;(*fr)!='\0';fr++)
            {
                        for(re=fr+1;(*re)!='\0';re++)
                                    {
                                                if((int)*re < (int)*fr)
                                                {
                                                            temp=*re;
                                                            *re=*fr;
                                                            *fr=temp;
                                                }
                                    }
            }

            puts("\n String in Ascending Order:- ");
            puts(str);
            getch();
}

/*
            =====OUT PUT=====

       1. Enter a String : KAUNDINYA

             String in Ascending Order:-
            AADIKNNUY

       2. Enter a String : BHARATH

             String in Ascending Order:-
            AABHHRT

       3. Enter a String : ABCDEFGH

             String in Ascending Order:-
            ABCDEFGH

*/

0 comments:

Post a Comment