Skip to content

Instantly share code, notes, and snippets.

@ThatOneCubanDude
Created March 26, 2020 22:47
Show Gist options
  • Save ThatOneCubanDude/7c151e4aa7576afc4990de0417daaabb to your computer and use it in GitHub Desktop.
Save ThatOneCubanDude/7c151e4aa7576afc4990de0417daaabb to your computer and use it in GitHub Desktop.
My solution to CS50x Problem Set 1 - Mario(more comfortable). Feel free to critique or ask questions.
#include <cs50.h>
#include <stdio.h>
//mentions function "get_height" so we can use it later on
int get_height(string prompt);
//main code
int main(void)
{
int n = get_height("Height: ");
//creats first (ascending) pyramid
for (int column = 0; column < n; column++)
{
for (int row = 0; row < n; row++)
{
if (column + row < n - 1)
{
printf(" ");
}
else
{
printf("#");
}
}
// creates space between pyramids
printf(" ");
//creates the second (descending) pyramid
for (int row2 = 0; row2 < n; row2++)
{
if (row2 - column < 1)
{
printf("#");
}
}
printf("\n");
}
}
//creates function "get_height" that asks user for a number between 1 and 8
int get_height(string prompt)
{
int n;
do
{
n = get_int("%s", prompt);
}
while (n < 1 || n > 8);
return n;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment