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

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

Page 1 of 1

3 Replies - 5453 Views - Last Post: 30 December 2008 - 04:50 AM Rate Topic: -----

#1 meriya_vino  Icon User is offline

  • New D.I.C Head

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

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

Post icon  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  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1148
  • View blog
  • Posts: 7,149
  • 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.

Post your code like this: :code:

Thanks.
Was This Post Helpful? 0
  • +
  • -

#3 Christopher Elison  Icon User is offline

  • D.I.C Head

Reputation: 39
  • View blog
  • 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 :D

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

Was This Post Helpful? 0
  • +
  • -

#4 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • 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. :^:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1