Code this logic :P
Box in a Box Idea is to take a number as input and print a pattern of boxes If input is 2, two boxes are to be printed - one inside the other Smallest box will be of size 3*3, the next bigger box will be 5*5, the next one will be 7*7, so on and so forth For input 1, then draw a box of dimensions 3*3 For input 2, outer box will be 5*5, inner will be 3*3 For input 3, outer box will be 7*7, with 2 more inner boxes All boxes will be top left aligned as shown in the figure
Like this, for n=2? ***** ***** ** ** ***** ***** Would look nicer if the boxes are separated. This way it looks more like a solid box with a hole than boxes in a box. lol
* * * * * * * * * * * * * * * * * * * this is for n = 2
How about this, centred box in a box, floating inside like magic, lol. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * PS I wish there's a way to specify fixed space Courier font for printer graphs.
Do you ask a general code to be able to cope with input 4, 5, .. ?
Hi, thought this looked like a nice challenge so I made something in python: def DrawBoxes(numberOfBoxes): print("*"*(numberOfBoxes *2+1)) #top line print("*" + " *"*numberOfBoxes) #second line for n in range(1,numberOfBoxes): print("*"*(n*2+1) + " *"*(numberOfBoxes-n)) print("*" + " "*(n*2) + " *"*(numberOfBoxes-n)) print("*"*(numberOfBoxes *2+1)) #bottom line It uses the layout that rvc suggested, mainly because it looked the simplest to code :P
Join our real-time social learning platform and learn together with your friends!