Last active
September 9, 2017 23:15
-
-
Save OxiBo/2069119806dfb084d7cfadaeaae98422 to your computer and use it in GitHub Desktop.
CS50 week 1/week 8 Mario_less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* CS50 week1 mario_less | |
*/ | |
#include <stdio.h> | |
#include <cs50.h> | |
int main (void) | |
{ | |
int height; | |
int h=1; | |
do | |
{ | |
printf ("height:"); | |
height=get_int(); | |
} | |
while (height<0||height>23); | |
int i=0; | |
int t=height; | |
for (i=0; i<height; i++) | |
{ | |
int s=0; | |
for (s=0; s<t-1; s++) | |
{ | |
printf(" "); | |
} | |
int n=0; | |
for (n=0; n<h+1; n++) | |
{ | |
printf("#"); | |
} | |
h++; | |
t--; | |
printf("\n"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#print Mario piramid_less comfortable | |
def main(): | |
#get positive integer from a user (the height) greater than 0 smaller then 23 | |
import cs50 | |
while True: | |
print("height:", end="") | |
height=cs50.get_int() | |
if height>0 and height<=23: | |
break | |
width=height-1 #creat a variable to remember amount of spaces to print in each row | |
h=2 #create a variable to remember the amount of # to print in each row | |
#iterate over each row | |
for i in range(height): | |
#print spaces in each row | |
print(" "*width, end="") | |
#print # in each row | |
print("#"*h, end="") | |
h+=1 #increment amount of # to print in the next row | |
width-=1 #decrement amout of spaces to print in the next row | |
print ("") #print a new line | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment