I was able to make the Mario's pyramid from Problem Set 1, (I know it should be right alligned, not left). This is the code, and it is working fine when I execute the program, but I don't seem to understand the logic or the need of writing j <= i in the //Loop for columns.

//Loop for new row
for (int i = 0; i < n; i++)

        //Loop for colums (#)
        for (int j = 0; j <= i; j++)



Can someone explain to me why this makes printf show 1 then 2 then 3 hashes, and so on, please? Sorry about possible english errors, my first language is Portuguese. Thanks!


What your code does is, for every time it increases i, it prints '#' 1 times more than i, followed by a /n (line break). To make right aligned, you need another for loop behind the 'loop for columns' that looks like for (int j = 0; j <= n - i; j++) and prints ' ' instead of '#'. Also, your english was fine :). Good luck!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .