Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <stdio.h>
- int main(void){
- int height = 0;
- do{
- printf("height: "); //ask for a height
- height = get_int();
- }while(!(height >=1 && height <=23)); //prompt again if the height is not between [1,23]
- for(int i = 1; i <= height;i++){//loop equal to the height
- for(int s = 1; s <= i*-1 + height;s++){//print spaces equal to the height - the line
- printf(" ");
- }
- for(int t = 1; t <= i + 1; t++){//print #s equal to the line + 1
- printf("#");
- }
- printf("\n");//move to the next line
- }
- }
- //Daniel Lawson
- /*
- prompt for input, use a do while to make sure it's [1,23]
- have a for loop that loop repeats equal to the height
- -have two for loops nested inside the for loop
- 1. print spaces equal to the height - line
- 2. print #s equal to the line + 1
- move to the next line
- */
- /*
- provided sample output:
- username:~/workspace/pset1 $ ./mario
- height: 8
- ##
- ###
- ####
- #####
- ######
- #######
- ########
- #########
- input must be 1-23
- */
Advertisement
Add Comment
Please, Sign In to add comment