program to sort string in accending order in c.

/* program to sort a string in accending order  in c*/


    #include<stdio.h>
    #include<string.h>
    void main()
    {
        char s[20],a[20];
        int length,i,j=97,x,k=0;
        printf(“enter a string”);
        scanf(“%s”,s);
        length=strlen(s);
        while(j<=122)  // ascii value of “a-z” is in between “97-122”
        {
           for(i=0;i<=length-1;i++)
           {
               x=s[i];
               if(x==j)
               {
                a[k]=s[i];
                k++;
               }
           }
           j++;
        }
        printf(“%s”,a);
        
    }

2 thoughts on “program to sort string in accending order in c.

Leave a Reply

Your email address will not be published.