daniel_lawson9999

Daniel Lawson Mario Program

Sep 23rd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. #include <cs50.h>
  2. #include <stdio.h>
  3.  
  4. int main(void){
  5.     int height = 0;
  6.     do{
  7.         printf("height: ");   //ask for a height
  8.         height = get_int();
  9.     }while(!(height >=1 && height <=23)); //prompt again if the height is not between [1,23]
  10.  
  11.     for(int i = 1; i <= height;i++){//loop equal to the height
  12.         for(int s = 1; s <= i*-1 + height;s++){//print spaces equal to the height - the line
  13.             printf(" ");
  14.         }
  15.         for(int t = 1; t <= i + 1; t++){//print #s equal to the line + 1
  16.             printf("#");
  17.         }
  18.         printf("\n");//move to the next line
  19.     }
  20. }
  21. //Daniel Lawson
  22. /*
  23. prompt for input, use a do while to make sure it's [1,23]
  24. have a for loop that loop repeats equal to the height
  25. -have two for loops nested inside the for loop
  26.     1. print spaces equal to the height - line
  27.     2. print #s equal to the line + 1
  28.     move to the next line
  29. */
  30. /*
  31. provided sample output:
  32. username:~/workspace/pset1 $ ./mario
  33. height: 8
  34.        ##
  35.       ###
  36.      ####
  37.     #####
  38.    ######
  39.   #######
  40.  ########
  41. #########
  42.  
  43.  
  44. input must be 1-23
  45. */
Advertisement
Add Comment
Please, Sign In to add comment