Skip to content

Instantly share code, notes, and snippets.

@ThatOneCubanDude
Created March 26, 2020 22:46
Show Gist options
  • Save ThatOneCubanDude/6c27c7c2c64a41cbaa95d2dad1f92ffa to your computer and use it in GitHub Desktop.
Save ThatOneCubanDude/6c27c7c2c64a41cbaa95d2dad1f92ffa to your computer and use it in GitHub Desktop.
My solution to CS50x Problem Set 1 - Mario(less 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: ");
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (i + j < n - 1)
{
printf(" ");
}
else
{
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