• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating a pyramid  RSS feed

 
Andrea Menjivar
Greenhorn
Posts: 25
1
Android
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, can anyone help me with this? I need to make a pyramid that displays these numbers but I have no idea how to do this. I end up getting different numbers besides the ones I need.
                          1                           
                                              1   2   1                       
                                         1   2   4   2   1                   
                                     1   2   4   8   4   2   1             
                                1   2   4   8  16   8   4   2   1        
                            1   2   4   8  16  32  16   8   4   2   1    
                       1   2   4   8  16  32  64  32  16   8   4   2   1  
                 1   2   4   8  16  32  64 128  64  32  16   8   4   2   1

This is the code I'm working with:

 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  I end up getting different numbers besides the ones I need.

Please copy the program's output and paste it here to show what you are talking about.
 
Andrea Menjivar
Greenhorn
Posts: 25
1
Android
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what it currently looks like
Screenshot-(93).png
[Thumbnail for Screenshot-(93).png]
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, that looks like a good shape.  Now you need to change what numbers are printed in the shape. 
What is the relationship between the current numbers that are printed and the desired numbers?
 
Fred Kleinschmidt
Bartender
Posts: 571
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your second loop, you should be printing the  (j-1)th power of 2, not j. Same with third loop.
But you should change the number of spaces printed in the first loop depending on the number of row and therefore the number of digits in the largest value, so that the pyramid will look symmetrical.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!