Question: hello, can someone help with my homework, the problem that I have is that I need to return how many times the count has added

hello, can someone help with my homework, the problem that I have is that I need to return how many times the count has added but my pass by reference is not working and it is returning 0.

I added comments on where to look. It should be easy to spot.

please let me know if you need more info thanks!

In C++

Here is the code

#include

#include

#include

#include

#include

using namespace std;

int fib1(int n, int & count) { // I am passing by reference but not returning the value that I need to

if (n <= 1) {

return n;

} else {

count++; //here is the count that I need to return

return fib1(n - 1, count) + fib1(n - 2, count);

}

}

void fib(int n) {

int cot=0;

int f[n + 2];

int i;

f[0] = 0;

f[1] = 1;

for (i = 2; i <= n; i++) {

f[i] = f[i - 1] + f[i - 2];

cot++;

}

cout<<"The count was " << cot<

// return f[n];

cout<<" The "<< n<< "number was" <

};

int main() {

int count = 0;

int num1;

cout << "Find the fib" << endl;

cin >> num1;

auto start = chrono::high_resolution_clock::now();

ios_base::sync_with_stdio(false);

fib(num1);

auto end = chrono::high_resolution_clock::now();

// Calculating total time taken by the program.

double time_taken =

chrono::duration_cast(end - start).count();

time_taken *= 1e-9;

cout << "Time taken by program is : " << fixed << time_taken

<< setprecision(9);

cout << " sec" << endl;

start = chrono::high_resolution_clock::now();

ios_base::sync_with_stdio(false);

cout<

end = chrono::high_resolution_clock::now();

// Calculating total time taken by the program.

double time_taken_ =

chrono::duration_cast(end - start).count();

time_taken_ *= 1e-9;

cout << "Time taken by program is : " << fixed << time_taken

<< setprecision(9);

cout << " sec" << endl;

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!