Thread: A little help please

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    25

    A little help please

    Here is something that I can't figure out... How can I make a program that prints a

    Number triangle with height = b
    Example: b=5
    Output is
    55555
    4444
    333
    22
    1

    ?? Thanks in advance!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What have you tried?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    25
    Quote Originally Posted by laserlight View Post
    What have you tried?
    Code:
    counter = 1;
    	b = 1;
    	do {
    	printf("%d\n", counter);
    	}while (counter <=b);
     	b++;
    This. It only prints single numbers.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why would you start with a low number if your output is supposed to start with a high number? It's almost as if you don't know how to count backwards. Try Googling "how do I count backwards".


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

  5. #5
    Registered User
    Join Date
    Jul 2011
    Posts
    25
    Quote Originally Posted by quzah View Post
    Why would you start with a low number if your output is supposed to start with a high number? It's almost as if you don't know how to count backwards. Try Googling "how do I count backwards".


    Quzah.
    Oh.... Sorry bout that. Thank you. Such a genius, (.m^m.)
    That didn't helped. That was a practice code. Of course I know how to count.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by bummielove View Post
    Of course I know how to count.
    Not according to any of the code you have posted. How about you try again?

    Hint: Start at 5 and count backwards.


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

  7. #7
    Registered User
    Join Date
    Jul 2011
    Posts
    25
    Quote Originally Posted by quzah View Post
    Not according to any of the code you have posted. How about you try again?

    Hint: Start at 5 and count backwards.


    Quzah.
    Code:
     #include <stdio.h>
    
    int main ()
    {
    
    	int x = 1, y = 1, b;
    	
    
    	printf("What value for b did you enter? ");
    	scanf("%d", &b);
    	y = y*b;
    	while ( y <= b){
    	printf("%d", x);
    	y++;
    	}
    	{
    	printf("\n");
    	x++;
    	}
    
    return 0;
    
    }
    How about this one? It's all mixed now! =))

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Backwards is sort of a key word here. How do you get from 5 to 4? From 4 to 3? Etc.?

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Good lord.... try this....
    Code:
    #include <stdio.h>
    
    int main (void)
      { int row, col;
    
         for( row = 9; row > 0; row--)
           { for (col = row; col > 0; col--)
                 printf("%d",row);
              printf("\n"); }
    
       return 0; }
    Like the guys said... count BACKWARDS....

Popular pages Recent additions subscribe to a feed