I'm having alittle trouble having my code create the pyramid for Mario. The code that is below prints out the user input but lets say the user puts in 4 it would print out vertically.


Here is the code

for (int i = 1; i<= n; i++) 
// print spaces (height - 1)
for ( int j = 1; j <= (n-1); j++)
       printf(" ");
    //print #'s
    for (int k = 1; k<=2;k++)
    // new line 

1 Answer 1


Your code prints out 4 lines of 2 #'s on each line. That's exactly what the code that you wrote should do. The good news is that you have written code that produces the right number of output lines.

But the assignment is to print out a half-pyramid with the correct number of spaces and #s on each line. Now, you need to do the next step and add that code to the program!

Part of the policy of this forum is to help people resolve problems with their coding. That requires that question submitters must first write the code and then present an explanation of the problem and a description of what was attempted to resolve it. Simply writing code for others is prohibited by the Honor Code policies specified by Harvard. So, please give it another shot and see how far you get. If you're absolutely stumped, try again with the relevant questions and information.

If this answers your question, please accept this answer to remove the question from the unanswered question pool. Let's keep up on forum housekeeping. ;-)

You must log in to answer this question.

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