I have searched the forum for an answer to my question but the code from others confused me. My pyramid keeps printing upside down and I'm not really sure why. I am not looking for an answer but rather an explanation to lead me in the right direction. Below is my code -
Think about what the for loops and i and j are doing. The outer loop is counting the rows from 0 to n-1, which is ok. But look at the inner loop:
for (j= i; j < n; j++)
Now, say that n = 5. On the first outer loop, i=0. That means that j starts at 0 and counts to 4, so it'll print 5 hashes. Next pass, 1 to 4 and so on. That's why the pyramid is upside down.
The inner loop, the number of hashes on a given line depends only on the line number and has nothing to do with the total number of lines.
On the other hand, the number of leading spaces depends completely on both the line number and the total number of lines! Think about that! ;-)
If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)