How to draw squares inside squares using for loops? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

How to draw squares inside squares using for loops?

Hi guys, so we were given this practice task in which we have to get the size of outer square from user and then we have to ask the number of inner squares they want to be printed inside (this is to be done using for loop only) I have managed to make the outer square but when I try to draw outer square + inner squares,for some reason it starts drawing some weird shapes :( I've tried a lot for a couple of hours but couldn't figure anything out. So, if anyone could help me, it would be much appreciated. thanks.

21st May 2018, 9:47 PM
shahbaz naseer
shahbaz naseer - avatar
11 Respostas
21st May 2018, 10:01 PM
shahbaz naseer
shahbaz naseer - avatar
21st May 2018, 10:13 PM
shahbaz naseer
shahbaz naseer - avatar
0
怌ļ¼Øļ¼”ļ¼°ļ¼°ļ¼¹ ļ¼“ļ¼Æ ļ¼Øļ¼„ļ¼¬ļ¼°ć€ yep got it to some point but still confused about the placement of loop for the inner square. should it be in the mid? like after the line for boundary line?
21st May 2018, 10:08 PM
shahbaz naseer
shahbaz naseer - avatar
0
怌ļ¼Øļ¼”ļ¼°ļ¼°ļ¼¹ ļ¼“ļ¼Æ ļ¼Øļ¼„ļ¼¬ļ¼°ć€ both are same. for example if the size is 17 then the height is 17 and the width is also 17
21st May 2018, 10:14 PM
shahbaz naseer
shahbaz naseer - avatar
0
sure
21st May 2018, 10:17 PM
shahbaz naseer
shahbaz naseer - avatar
0
actually all we were told was that each inner square will be after an interval of 2 empty spaces. forgot to mention again :/ really sorry! and we also have to figure out if the number of inner squares that user has entered is possible or not which I was able to do.
21st May 2018, 10:22 PM
shahbaz naseer
shahbaz naseer - avatar
0
+__+ like this. "_" represents a space actually there will be nothing in this area just a space
21st May 2018, 10:34 PM
shahbaz naseer
shahbaz naseer - avatar
0
it's 1 XD
21st May 2018, 10:42 PM
shahbaz naseer
shahbaz naseer - avatar
0
hahahaha šŸ˜‚ true that! I spent about 6-7 hours trying to do it! i know I'll figure it out but it's hard XD now it's 4 AM here n I'm done with this XD
21st May 2018, 10:52 PM
shahbaz naseer
shahbaz naseer - avatar
0
haha sure! will check later in the morning XD
21st May 2018, 10:55 PM
shahbaz naseer
shahbaz naseer - avatar
0
hahaha it's alright! it works :D
21st May 2018, 11:12 PM
shahbaz naseer
shahbaz naseer - avatar