Skip to content

Instantly share code, notes, and snippets.

@waynewallace
Created May 11, 2020 16:58
Show Gist options
  • Save waynewallace/8ded877225439529df7ff21ef618fc9e to your computer and use it in GitHub Desktop.
Save waynewallace/8ded877225439529df7ff21ef618fc9e to your computer and use it in GitHub Desktop.
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