C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-16-2008, 12:08 PM   #1
Registered User
 
Join Date: Sep 2008
Posts: 37
Question Using While Loop to write a program

How can i start the logic for this program is there a formula or do you all know where can i see a similar example, please.

Program that uses the while loop to compute and print the sum of a given number of squares.

Ex. If 5 is Input program will print 55

I'm not asking to do this for me just want Ideas.

I'm kind of slow at the beginning of evrything but at the end I'll never forget it.
Cyberman86 is offline   Reply With Quote
Old 09-16-2008, 12:17 PM   #2
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,740
The idea is given to you: "use the while loop to compute and print the sum of a given number of squares".

So -- figure out the conditions on the while loop (i.e., when should it stop) and what computation needs to happen each step through.
tabstop is offline   Reply With Quote
Old 09-16-2008, 12:52 PM   #3
Banned
 
master5001's Avatar
 
Join Date: Aug 2001
Location: Visalia, CA, USA
Posts: 3,699
if x = something

n := 0

for each x

n := n + x * x

x := x - 1

loop

Right? I mean I know its sort of pseudo-code and sort of a hybrid between basic and pascal, but you get the picture. The trick is getting the input and having a second variable maintain the summation.
master5001 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C keep a loop going whilst program continues on fortune2k C Programming 6 03-11-2009 08:44 AM
Dynamic Link to DLL with LoadLibrary corrupts control loop Ramses800 C Programming 8 12-01-2008 10:09 AM
Issue with program that's calling a function and has a loop tigerfansince84 C++ Programming 9 11-12-2008 01:38 PM
Need help with a loop program hieugene C++ Programming 12 10-11-2006 02:42 AM
Read a file into a loop program TimeClock C Programming 5 07-17-2003 06:29 PM


All times are GMT -6. The time now is 02:20 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22