#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    1
    Rep Power
    0

    Print the contents of string array in ascending order


    Hi everyone,

    im trying to learn c programming. i have a question

    i have a string array and im inserting value like "microsoft" into that array and i want to print the contents in the following format

    microsoft

    microsof

    microso

    micros

    .
    .
    .
    .

    m
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    109
    Rep Power
    3
    Code:
    #include<stdio.h>
    
    int main()
    {
    
        char array[]={'m','i','c','r','o','s','o','f','t'};
    
    
        int n;
    
    
        int i;
    
    
          for(n=9;n>0;--n)
          {
            for(i=0;i<n;++i)
                printf("%c", array[i]);
                putchar('\n');
          }
    
        getch();
        return 0;
    }
    Notice that putchar('\n') is not associated with the inner for, the prog enters there only after completing the inner loop for a certain value of 'n'. Then it goes back to the outer loop, decreases 'n' and enters the inner loop again.

    It's just one version of many, but you get the general idea.

    Comments on this post

    • eramit2010 disagrees : i think no need to provide complete code to anyone.

IMN logo majestic logo threadwatch logo seochat tools logo