CS50_Labs/Lab1/mario/mario.c

53 lines
942 B
C

#include <cs50.h>
#include <stdio.h>
//prototype declaration
int user_input(void);
void spacing(int height);
int main(void)
{
int height = user_input() + 1;
//creates a pyramid
for (int i = 1; i < height; i++)
{
spacing(height - i);
//creates first left side, than space, than right side of pyramid
for (int k = 1; k < 3; k++)
{
for (int j = 1; j < i + 1; j++)
{
printf("#");
}
if (k==1)
{
printf(" ");
}
}
printf("\n");
}
}
//get positive integer from user
int user_input(void)
{
int height;
do
{
height = get_int("Height: ");
}
while (height < 1 || height > 8);
return height;
}
// creates spacing on the left side of the pyramid
void spacing(int height)
{
for (int i = 1; i < height; i++)
{
printf(" ");
}
}