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 PostIf you use a FOR loop from 1 to N, this loop would control each line.
Then inside that FOR loop you have more loops that control the pattern of each line.Your job is to figure out how to create the line pattern. What is the same in …
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 PostI see that the square, in this case, is a 9 x 9 square, and that each descending number appears as a multiple of 8 (There are 8 4's, 16 3's, 24 2's, and 32 1's), but i'm not sure of any other patterns.
You're kidding.....
Line 1: 111111111 …
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 5,225 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.