Skip to content

Instantly share code, notes, and snippets.

@waynewallace
Created May 11, 2020
Embed
What would you like to do?
Harvard C Assignment 1
// mario.c
//
// prints pyrimid block wall with stair step on both sides with valley of
// spaces in the middle
//
// Sample output
//
// Height:
// 4
// # #
// ## ##
// ### ###
// #### ####
#include <cs50.h>
#include <stdio.h>
int main(void)
{
int height;
// get user input
// valid input positive numbers between 1 and 8 inclusive
do
{
height = get_int("Height:\n");
}
while (height < 1 || height >= 9);
// print rows of the wall
for (int rowCount = 1; rowCount <= height; rowCount++)
{
// add spaces as needed to each row
for (int spacesToAdd = 0; spacesToAdd <= height; spacesToAdd++)
{
if (rowCount < spacesToAdd)
{
printf(" ");
}
}
// print half the row of # blocks
for (int blockCount = 0; blockCount < rowCount; blockCount++)
{
printf("#");
}
// print the space in between
printf(" ");
// print the other half the row of # blocks
for (int blockCount = 0; blockCount < rowCount; blockCount++)
{
printf("#");
}
// print end of line return
printf("\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment