C++ Programming
#22
RE: C++ Programming
lol. I'm trying to figure out this one program I was shown the code to write.. I understand all but one part.. basically what it does is calculate the nth number in the Fibonacci series.
For those who don't know, the Fibonacci series is just taking the two previous numbers and adding them to get the new number, starting with 1,1 ... so, it goes like this:
1,1,2,3,5,8,13....
In this program, you can input 4, to find what the 4th number in the series would be... which comes out to be 3.
...only problem is I don't understand part of the code, so I'm stumped. lmao
For those who don't know, the Fibonacci series is just taking the two previous numbers and adding them to get the new number, starting with 1,1 ... so, it goes like this:
1,1,2,3,5,8,13....
In this program, you can input 4, to find what the 4th number in the series would be... which comes out to be 3.
...only problem is I don't understand part of the code, so I'm stumped. lmao
#24
RE: C++ Programming
I figured it out. Here's the code though:
Lines 1-6 were comments.
I put 100 into the program and it ran for 40 minutes before I had to shut my computer down and leave work, hahahahaha
Code:
7: #include <iostream.h> 8: 9: int fib(int n); 10: 11: int main() 12: { 13: 14: int n, answer; 15: cout << "Enter number to find: "; 16: cin >> n; 17: 18: cout << "\n\n"; 19: 20: answer = fib(n); 21: 22: cout << answer << " is the " << n << "th Fibonacci number\n"; 23: return 0; 24: } 25: 26: int fib (int n) 27: { 28: cout << "Processing fib(" << n << ")... "; 29: 30: if (n < 3 ) 31: { 32: cout << "Return 1!\n"; 33: return (1); 34: } 35: else 36: { 37: cout << "Call fib(" << n-2 << ") and fib(" << n-1 << ").\n"; 38: return( fib(n-2) + fib(n-1)); 39: } 40: }
I put 100 into the program and it ran for 40 minutes before I had to shut my computer down and leave work, hahahahaha
#30
RE: C++ Programming
ORIGINAL: mysterio2099
LOL, who put me back on P/A?? Patrick told me he was taking me off yesterday... didn't know anyone could over rule the big dawg?
[:-]
LOL, who put me back on P/A?? Patrick told me he was taking me off yesterday... didn't know anyone could over rule the big dawg?
[:-]