This problem is to print a square using a number that the user enters, which would be in the center. If the user entered a 5, then the program should output this:
111111111
122222221
123333321
123444321
123454321
123444321
123333321
122222221
111111111
If you're wondering, this was not a homework assignment. It was on a quiz, and I did not know how to do it. So if someone could give me at the very least some guidance on how to solve this problem, then that'd be nice. I know that I need to use for loops, but I'm not quite sure how. Thank you for your time and assistance.
rfrapp 17 Junior Poster in Training
Recommended Answers
Jump to PostSeemingly, the number has to be between 1 and 9, right?
...but if this is on a quiz, why would you want someone else to answer it?
Jump to PostThe program sounds fun so I did it myself..used a whole mess of if else statements inside an inner loop...though the program might be simplified if you use a recursive function but I'm not sure how to do this yet
Jump to PostI really do like programming, it's just that the problem solving part is difficult for me.
I have devastating news for you.
I forgot to mention that I'm relatively new to C++, and I have no idea what most of that means :p
Don't fret. I've been using C++ for …
Jump to PostYou can start by reading the Daniweb Posting Rules. Then you can Read This Before Posting a Question. You also might want to read everything that has already been posted in this thread.
Jump to PostThis looked interesting so I had a go. Did it in Ruby so it wouldn't be of use to anyone with Java, C or C++ homework :)
puts "enter a number:" number = gets.to_i # calculate the dimensions of the square length = ((number-1) * 2) + …
All 17 Replies
thines01 401 Postaholic Team Colleague Featured Poster
zeroliken 79 Nearly a Posting Virtuoso
thines01 401 Postaholic Team Colleague Featured Poster
rfrapp 17 Junior Poster in Training
rfrapp 17 Junior Poster in Training
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
rfrapp 17 Junior Poster in Training
Dman01 10 Light Poster
Tumlee 42 Junior Poster in Training
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
MandrewP 60 Junior Poster in Training
Tumlee 42 Junior Poster in Training
m4ster_r0shi 142 Posting Whiz in Training
WaltP commented: If not, maybe the instructor isn't ready to teach them... -4
m4ster_r0shi 142 Posting Whiz in Training
Armugam Rajashekar 0 Newbie Poster
Reverend Jim 4,780 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
pty 882 Posting Pro
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.