64 630
Assignments Done
99,1%
Successfully Done
In September 2018

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 order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions