techPowerUp! Forums Noob programmer help
 techPowerUp! Register FAQ Social Groups Search Today's Posts Mark Forums Read

Nov 23, 2009, 06:23 PM   #1
Lampmaster

Join Date: Aug 2009
Location: Washington The State
Posts: 149 (0.11/day)
Thanks: 35
Thanked 17 Times in 14 Posts

System Specs

Noob programmer help

Hi, I was just wondering if it was possible to take this C++ code and make it to where it sums using the Fibonacci sequence.

Quote:
 cin >> n; sum = 0; ii = 0; // Loop control variable while (ii <= n) { sum = sum + ii; ii++; } // While loop

Last edited by Lampmaster; Nov 23, 2009 at 08:07 PM.

 Nov 25, 2009, 02:40 PM #2 Kreij Hardcore Monkey Moderator     Join Date: Feb 2007 Location: Cheeseland (Wisconsin, USA) Posts: 12,133 (5.27/day) Thanks: 591 Thanked 5,494 Times in 2,938 Posts System Specs Need more information. Is the inputted variable "n" the number of Fibonacci series numbers that you want, or do you want to generate numbers in the series until you hit "n"? For instance, if n=3 do you want "0,1,1" (first three numbers in the series) or do you want "0,1,1,2,3" (numbers up to 3 in the series)? __________________ Cloud (noun, singular): A dynamic arrangement of multiple potential single points of failure, with a user at one end and their data at the other. Get more tech news on a wide variety of topics at NextPowerUp
Nov 25, 2009, 03:07 PM   #3
qamulek

Join Date: Feb 2008
Posts: 185 (0.10/day)
Thanks: 51
Thanked 26 Times in 26 Posts

Just a quick guess(based on the limited information as pointed out by kreij):
Quote:
 cin >> n; sum1 = 0; sum2= 1; sumtemp; ii = 0; // Loop control variable while (ii < n) { sumtemp= sum1 + sum2; sum2=sum1; sum1=sumtemp ii++; } // While loop //output is in sum1 and *should* contain the nth iteration of the fibonacci sequence
__________________

avatarsuperduper[youtube]: ..."stop lieing feel ur self owned!"

 The Following User Says Thank You to qamulek For This Useful Post:
 Nov 25, 2009, 04:20 PM #4 Kreij Hardcore Monkey Moderator     Join Date: Feb 2007 Location: Cheeseland (Wisconsin, USA) Posts: 12,133 (5.27/day) Thanks: 591 Thanked 5,494 Times in 2,938 Posts System Specs Depending upon your needs, you could also do it in an array as they lend themselves nicely to numeric series... Code: ```cin >> count; // Create dynamically sized array based on input. int* fibarray; fibarray = new int[count]; // Set first two values fibarray[0] = 0; fibarray[1] = 1; int i = 2; // Loop variable which starts with 3rd array member while (i < count) { fibarray[i] = fibarray[i - 1] + fibarray[i - 2]; i++; }``` The above code does not do any error checking in the event that the count variable is set to a value less than 2. __________________ Cloud (noun, singular): A dynamic arrangement of multiple potential single points of failure, with a user at one end and their data at the other. Get more tech news on a wide variety of topics at NextPowerUp
 Nov 25, 2009, 06:40 PM #5 Lampmaster     Join Date: Aug 2009 Location: Washington The State Posts: 149 (0.11/day) Thanks: 35 Thanked 17 Times in 14 Posts System Specs Thanks for the replies. What Ijust noticed is I don't need to sum the Fibonacci sequence, I just need to output them. So if n = 3 it would output 1,1,2.
 Nov 25, 2009, 06:44 PM #6 Kreij Hardcore Monkey Moderator     Join Date: Feb 2007 Location: Cheeseland (Wisconsin, USA) Posts: 12,133 (5.27/day) Thanks: 591 Thanked 5,494 Times in 2,938 Posts System Specs Then either of the above two suggestions will work for you as they both use the inputted number as the number of series results you need. __________________ Cloud (noun, singular): A dynamic arrangement of multiple potential single points of failure, with a user at one end and their data at the other. Get more tech news on a wide variety of topics at NextPowerUp
 The Following User Says Thank You to Kreij For This Useful Post:
 Nov 25, 2009, 07:04 PM #7 Lampmaster     Join Date: Aug 2009 Location: Washington The State Posts: 149 (0.11/day) Thanks: 35 Thanked 17 Times in 14 Posts System Specs Alright cool, thanks.

 Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Hardware     General Hardware     Graphics Cards         NVIDIA         AMD / ATI     Overclocking & Cooling     Motherboards & Memory     System Builder's Advice     Cases, Modding & Electronics     Storage     Networking & Security     Project Logs     Audio, Video & Home Theater     Official Vendor Support & Information Forums         be quiet!         NZXT         Thermaltake Software     Games     Linux / BSD / Mac OS X     General Software     Programming & Webmastering Other     General Nonsense     Science & Technology     Folding@Home     World Community Grid (WCG)     Buy/Sell/Trade/Giveaway Forum     Hot Deals     techPowerUp! Club Forum www.techpowerup.com     Comments & Feedback     Reviews     Articles     News         TPU Frontpage Polls     Case Mod Gallery     Contests Our Software     GPU-Z         GPU-Z Test Builds         GPU-Z Translations     ATITool         ATITool Beta Area         ATITool Bug Reports     RBE     RealTemp

 Similar Threads Thread Thread Starter Forum Replies Last Post Wastedslayer Programming & Webmastering 3 Apr 9, 2009 11:31 PM SiCk Graphics Cards 19 Apr 10, 2006 12:47 PM karolpl2004 Overclocking & Cooling 12 Dec 3, 2005 11:03 PM

All times are GMT. The time now is 03:17 AM.

 -- Default Style -- Lightweight Contact Us - techPowerUp! - Archive - Top