![]() |
|
|
#1 | |
![]() Join Date: Aug 2009
Location: Washington The State
Posts: 149 (0.11/day)
Thanks: 35
Thanked 17 Times in 14 Posts
|
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:
Last edited by Lampmaster; Nov 23, 2009 at 08:07 PM. |
|
|
|
|
|
|
#2 |
|
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
|
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
|
|
|
|
|
|
#3 | |
![]() 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:
__________________
|
|
|
|
|
| The Following User Says Thank You to qamulek For This Useful Post: |
|
|
#4 |
|
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
|
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++;
}
__________________
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
|
|
|
|
|
|
#5 |
![]() Join Date: Aug 2009
Location: Washington The State
Posts: 149 (0.11/day)
Thanks: 35
Thanked 17 Times in 14 Posts
|
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.
|
|
|
|
|
|
#6 |
|
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
|
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: |
|
|
#7 |
![]() Join Date: Aug 2009
Location: Washington The State
Posts: 149 (0.11/day)
Thanks: 35
Thanked 17 Times in 14 Posts
|
Alright cool, thanks.
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Looking for a good Java Programmer | Wastedslayer | Programming & Webmastering | 3 | Apr 9, 2009 11:31 PM |
| Help a noob, X800GTO2 | SiCk | Graphics Cards | 19 | Apr 10, 2006 12:47 PM |
| im a noob at overclockin... help me! | karolpl2004 | Overclocking & Cooling | 12 | Dec 3, 2005 11:03 PM |