| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
help on simple Program
I am having a hard time doing this problem in c++.. I dont really understand it..here is is:
The Fibonacci Series 0, 1, 1, 2, 3, 5, 8, 13, 21,... begins with the terms 0 and 1 and has the property that each succeeding term is the sum of the two preceding terms (a.) Write a nonrecursive function fibonacci (n) that calculates the nth Fibonacci number. (b) Determine the largest int Fibonacci number that can be printed on your system. Modify the program of part (a) to use double instead of int to calculate and return Fibonacci numbers, and use this modified program to repeat part (b) thanks, Josh |
|
#2
|
||||
|
||||
|
sounds like homework?
do you have any code you've already written? that'd be a good place to start Hint: look into using an iterative loop |
|
#3
|
||||
|
||||
|
After reading it again, I love (b)
How do you determine that? what's the number that prints before your system crashes? |
|
#4
|
|||
|
|||
|
Yea, I know pretty dumb eh? I'll post what I have later on tonight, I am still working on it
|
|
#5
|
|||
|
|||
|
int fib = 0;
int t1 = 0; int t2 = 1; for (i = 1; i <= n; i++) { fib = t1 + t2; t1 = t2; t2 = fib; } |
|
#6
|
|||
|
|||
|
Hey!
The biggest integer you can print is 46386. However, the system does not crash after that number...I don't know why (it just starts back from the difference between the overflow number and 65536). But, after 46386 the next term would be 75.000 (and some!). Since the unsigned integer is up to 65536...I would say 46386 is the biggest term accepted by an int. Good Luck Anibal. PD: If you consider long int as int also....that's another story!! |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > help on simple Program |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|