To find the Square of the Numbers from 1 to 20 Using

Page 1 of 1

3 Replies - 17319 Views - Last Post: 30 December 2008 - 04:50 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=78562&amp;s=9af21383721e11724586524afed1673a&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 meriya_vino

Reputation: 0
• Posts: 1
• Joined: 28-December 08

To find the Square of the Numbers from 1 to 20 Using

Posted 29 December 2008 - 12:09 AM

Hi,

Please some one help in this

To find the Square of the Numbers from 1 to 20 Using
1. For loop 2. While loop 3. Do while loop 4. Goto Statement
Is This A Good Question/Topic? 0

Replies To: To find the Square of the Numbers from 1 to 20 Using

#2 BetaWar

• #include "soul.h"

Reputation: 1509
• Posts: 8,268
• Joined: 07-September 06

Re: To find the Square of the Numbers from 1 to 20 Using

Posted 29 December 2008 - 12:13 AM

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Thanks.

#3 Christopher Elison

Reputation: 39
• Posts: 230
• Joined: 29-December 08

Re: To find the Square of the Numbers from 1 to 20 Using

Posted 29 December 2008 - 05:35 PM

From what it looks like, you're being asked to produce 4 programs using those different looping techniques to achieve the same goal - displaying squares of numbers up to 20.

The first step is working out the logic to this, if you can get down on paper in plain English (or pseduocode) exactly what you want to do, then you're halfway there! For example:

```number = 1

Start loop here while number is less than 20
print number times number (Square of number)
Loop back

Exit

```

Now all you need to do is apply this using C++, which is pretty easy, let's take this for loop for example:

```for (i=1; i<=10; i++) {
std::cout << "Hello world!\n";
}

```

We're telling 'i' our number to start at 1 and then continue looping and adding 1 (increment) until we get to 10. This will print "Hello World!" ten times, it doesn't take much more fiddling to get this to multiply our number (i) by itself 20 times, which will be pretty much all you need for the for loop, I'll leave the rest to you

Good luck, buddy!

P.S: This is my first post on D.I.C

This post has been edited by Christopher Elison: 29 December 2008 - 05:38 PM

#4 Gloin

• Expert Schmexpert...

Reputation: 235
• Posts: 4,489
• Joined: 04-August 08

Re: To find the Square of the Numbers from 1 to 20 Using

Posted 30 December 2008 - 04:50 AM

And a good post it was. Very nice! Theory and explanatory examples without handing the exact solution.