Advertisement
JiriKiner

Mario less

Aug 15th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. // This program will draw a Mario's pyramid with the height as per the user's input from 1-8
  2.  
  3. #include <cs50.h>
  4. #include <stdio.h>
  5.  
  6. int main(void)
  7. {
  8.     // Declaring of the variable height with a value of 0
  9.     int height = 0;
  10.     // Do while loop to get user's input 1-8, otherwise asks again
  11.     do
  12.     {
  13.         // Prompts user for the height
  14.         height = get_int("Height: ");
  15.     }
  16.     // Checks if the input is between 1 and 8
  17.     while (height < 1 || height > 8);
  18.     // Draws pyramid with given height
  19.     for (int i = 0; i < height; i++)
  20.     {
  21.         for (int j = 0; j < height - 1 - i; j++)
  22.         {
  23.             printf(" ");
  24.         }
  25.         for (int k = 0; k < i + 1; k++)
  26.         {
  27.             printf("#");
  28.         }
  29.         printf("\n");
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement