0

Hello I am new to coding in c and not very familiar with it. I am getting the hash tags and I am using a - so I can see my spacing. Right now I am printing my pyramid the wrong way any help will be appreciated. Here is my code, and a sample of what is it printing.

# -## --###

do{

printf("Pick a number from 1 to 23: \n");
height= get_int();



/* Get the # and space to print out    */


int row = height + 1;
int space = height - row; 


for (row = 1 ; row <= height ; row++)
{


    for(hash =1; hash <= row; hash++ )
    {

    printf("#");

    }
    for(space = 1; space < row; space++)
    {

    printf("-");

    }


 printf("\n");


        }


    }while (height <= 0 || height > 23);
0

Swap the two inner loops, first do the spaces, then do the hashes. Also, inside your spaces loop, use something like space + row <= height, or space <= height - row or similar. You might have to adjust that, I just made that up.

1
  • I will try that thank you for the help! – Erica Hermosillo Jun 27 '17 at 1:41

You must log in to answer this question.

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