1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

number pattern

Discussion in 'C' started by programmerg, Dec 9, 2010.

  1. programmerg

    programmerg New Member

    Joined:
    Dec 9, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    print this pattern using for loop.

    [FONT=&quot]1 2 3 4[/FONT]
    [FONT=&quot] 5 6 7[/FONT]
    [FONT=&quot] 8 9[/FONT]
    [FONT=&quot] 10[/FONT]
    [FONT=&quot] 10[/FONT]
    [FONT=&quot] 9 8[/FONT]
    [FONT=&quot] 7 6 5[/FONT]
    [FONT=&quot]4 3 2 1[/FONT]
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Easy. Where are you stuck?
     
  3. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    can you figure out the last step?

    Code:
    #include <stdio.h>
    
    int main(){
        int i;
        for (i=0;i<20;i++){
            if (i<10)
                printf("%d ",i+1);//straight
            else
                printf("%d ",20-i);//reverse
        }
        
        getchar();
        return 0;
    }
    
    
     

Share This Page