Question #44004
write a c++ program that will output the following fibonacci numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144
1
Expert's answer
2014-07-07T15:35:02-0400
#include <iostream>using namespace std;int fibonacci(int n) {    if ( n == 0 || n == 1 ) {        return n;    }    if ( n < 0 ) {        return fibonacci(n+2) - fibonacci(n+1);    }    return fibonacci(n-1) + fibonacci(n-2);}int main() {    for (int i = 1; i < 13; i++ ) {        cout << fibonacci(i) << " ";    }    cout << endl;    return 0;}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS