# Answer to Question #44004 in C++ for julie

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

Expert's answer

`#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 orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment