Header Ads Widget

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);
        
    }

Post a Comment

1 Comments

  1. Your method of programing is very good by which I can understand easily

    ReplyDelete