Question: This program is supposed to write 1 1 2 3 5 8 13 21 but it probably does not. What is the program doing that

This program is supposed to write 1 1 2 3 5 8 13 21 but it probably does not. What is the program doing that is incorrect? (We're not asking you explain why the incorrect action leads to the particular outcome it does, and we're not asking you to propose a fix to the problem.)

#include using namespace std;

int fibonacci( int n ) { int tmp; int a = 1; int b = 1;

for (int i = 0; i < n-2; i++) { tmp = a+b; a = b; b = tmp; } return b; }

int* computeFibonacciSequence(int& n) { int arr[8]; n = 8; for (int k = 0; k < n; k++) { arr[k] = fibonacci( k ); } return arr; }

int main() { int m; int* ptr = computeFibonacciSequence(m); for (int i = 0; i < m; i++) { cout << ptr[i] << ' '; } return( 0 ); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!