#include <cs50.h>
#include <stdio.h>
int main(void)
{
printf("Please give men an int: ");
int h = GetInt();
char row;
char column;
char x;
for ( row = 0; row < h; row++)
{
for (column = 0; column > h ; column--)
{
printf(" ");
}
for (x = 0; x < row; x++)
{
printf("x");
}
printf("\n");
}
}
So this is what I've gotten so far, and it prints out a pyramid all right, but from the right.
I've used pen & paper a lot to draw out how many # and spaces there are on each line, but I'm struggling A lot with the equation and I'm beyond lost right now.
If anyone could give me some guidance towards the equation, I'd appreciate that so much, I know my problem is in the equation bit of it.
Thanks.
Edit:
#include <cs50.h>
#include <stdio.h>
int main(void)
{
printf("Please give men an int: ");
int h = GetInt();
int row;
int spaces;
int x;
for ( row = 0; row < h; row++)
{
for (x = 0; x < row; x++)
{
printf("x");
}
for (spaces = 0; spaces < h ; spaces++)
{
printf(" ");
}
printf("\n");
}
}
EDIT 2
#include <cs50.h>
#include <stdio.h>
int main(void)
{
printf("Please give men an int: ");
int h = GetInt();
int row;
int spaces;
int x;
for ( row = 0; row < h; row++)
{
//Print spaces
for (spaces = 0; spaces < row ; spaces++)
{
printf(" ");
}
//print Hashes
for (x = -1; x < row; x++)
{
printf("#");
}
//New line
printf("\n");
}
}
It now prints
#
##
###
####
#####
Why is this?