Like Tree1Likes
  • 1 Post By quzah

A little help please

This is a discussion on A little help please within the C Programming forums, part of the General Programming Boards category; Here is something that I can't figure out... How can I make a program that prints a Number triangle with ...

  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
    21,318
    What have you tried?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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.
    AndrewHunter likes this.
    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,185
    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

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