Hi, the next code is right. I mean it works. It gives the sequence of fibonaci numbers ...
but....Code:#include <iostream>
#include <iomanip>
using namespace std;
int fibo(int pos)
{
if(!pos)return 0;
if(pos==1)return 1;
int pos2=--pos;
int pos1=--pos;
int r1=fibo(pos1);
int r2=fibo(pos2);
int r=r1+r2;
return r;
}
int main()
{
int number;
cin>>number;
for(int p=0;p<number;++p)
{
int r=fibo(p);
cout<<p<<" "<<r<<endl;
}
cout<<endl;
return 0;
}
when I chage the lines:
for the lines:Code:int r1=fibo(pos1);
int r2=fibo(pos2);
int r=r1+r2;
It doen't work right. Apararently it should work the same.Code:int r=fibo(pos1)+fibo(pos2);
Can anyone give an explanation to this...?????
Thanks