[ask]pyramid number with loop

This is a discussion on [ask]pyramid number with loop within the C Programming forums, part of the General Programming Boards category; Code: #include<stdio.h> main() { int a,b,c; clrscr(); printf("input : ");scanf("%d",&c); for(a=1; a<=c; a++) { for(b=1; b<=a; b++) printf("%d",b); printf("\n"); } ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    12

    [ask]pyramid number with loop

    Code:
    #include<stdio.h>
    main()
    {
    int a,b,c;
    clrscr();
     printf("input : ");scanf("%d",&c);
    	for(a=1; a<=c; a++)
    	{
    		for(b=1; b<=a; b++)
    			printf("%d",b);
    			printf("\n");
    	}
    getch();
    }
    Output :
    1
    12
    123

    I try to make it like this:

    1
    12
    123
    12
    1

    but i always get this :

    1
    3
    12
    3
    123
    3

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You need to count up, and then back down. So...
    Code:
    for each row on the way up
        for each column on the way up
            print number
        print newline
    Then do the same thing for the way back down. (Hint: Don't reset the values of a and b, and count down.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    12
    its ok,
    ive done

    thx..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Mutiliplcation Program that uses a (do, while, and for loop)?
    By Debbie Bremer in forum C++ Programming
    Replies: 4
    Last Post: 10-11-2008, 06:04 PM
  3. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  4. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 07:26 PM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21