mirror of https://github.com/me50/kukemuna.git
53 lines
872 B
C
53 lines
872 B
C
|
|
#include <cs50.h>
|
||
|
|
#include <stdio.h>
|
||
|
|
|
||
|
|
void build_ramp(int height);
|
||
|
|
|
||
|
|
int main(void)
|
||
|
|
{
|
||
|
|
int height;
|
||
|
|
// Only accept positive integer
|
||
|
|
do
|
||
|
|
{
|
||
|
|
height = get_int("Height: ");
|
||
|
|
}
|
||
|
|
while (height < 1);
|
||
|
|
|
||
|
|
build_ramp(height);
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
void build_ramp(int height)
|
||
|
|
{
|
||
|
|
int space, row, block;
|
||
|
|
|
||
|
|
// Print row(s)
|
||
|
|
for (row = 0; row < height; row++)
|
||
|
|
{
|
||
|
|
// Print spaces
|
||
|
|
for (space = 0; space < height - row - 1; space++)
|
||
|
|
{
|
||
|
|
printf(" ");
|
||
|
|
}
|
||
|
|
|
||
|
|
// Print first set of blocks
|
||
|
|
for (block = 0; block <= row; block++)
|
||
|
|
{
|
||
|
|
printf("#");
|
||
|
|
}
|
||
|
|
|
||
|
|
// Print gap
|
||
|
|
printf(" ");
|
||
|
|
|
||
|
|
// Print other set of blocks
|
||
|
|
for (block = 0; block <= row; block++)
|
||
|
|
{
|
||
|
|
printf("#");
|
||
|
|
}
|
||
|
|
|
||
|
|
// Print newline
|
||
|
|
printf("\n");
|
||
|
|
}
|
||
|
|
}
|