Answer the question
In order to leave comments, you need to log in
Why doesn't the program work, c++ fibonacci?
#include <iostream>
using namespace std;
int fibonacci(int n)
{
if (n == 0) return 0;
else if (n==1 && n==2) return 1;
else return fibonacci(n-1)+fibonacci(n-2);
}
int n;
int main(){
cout<<"Wprowadz numer liczbe"<<endl;
cin >> n;
cout << "Liczba Fibonacci numerowane "<< n <<" jest " << fibonacci(n) << endl;
return 0;
}
Answer the question
In order to leave comments, you need to log in
It doesn't work because you are not using a debugger. Until you learn how to use a debugger, you won't be able to write programs harder than "Hello world" yourself.
Let's start with the fact that the error here is even in the first line.
#include //что?
....
else if (n==1 && n==2) return 1; //здесь должно быть "или", а не "и" (это и есть проблема функции)
....
cout<<"Wprowadz numer liczbe"<> n;
//Что, по вашему, оно должно делать?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question