Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int Fibonacci(int n) {
- int t1=0, t2=1,nextTerm;
- if (n < 0) {
- return -1;
- }
- if (n == 0) {
- return 0;
- }
- else if (n == 1) {
- return 1;
- }
- for (int i = 1; i <= n+1; ++i) {
- if (i == 1) {
- continue;
- }
- if (i == 2) {
- continue;
- }
- nextTerm = t1 + t2;
- t1 = t2;
- t2 = nextTerm;
- }
- return nextTerm;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement