Question: What is wrong with this code in C + + , meant to use user defined function ( no recursion ) to calculate fibonacci sequence?

What is wrong with this code in C++, meant to use user defined function (no recursion) to calculate fibonacci sequence?
#include
using namespace std;
int x;
int fibonacci(int){
int new_number =(x -1)+(x -2);
cout << new_number;
return new_number;
}
int main()
{
int n =0;
int new_number =0;
int x =0;
cout <<"
Enter number up to which you would like a fibonacci sequence for "<< endl;
cin >> x;
for (int i =0; i = x; i++){
if (x ==0)
cout << x << endl;
else if (x ==1)
cout << x << endl;
else {
i = x;
x++;
fibonacci(x);
}
cout << new_number << endl;
}
}

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 Programming Questions!