Category : fibonacci

Here I need to get the last five digits of a Fibonacci number for large n’s, here is the code: #include <iostream> #include <cmath> using namespace std; const int p = 10; long double Fibonacci(unsigned nn) { long double fn; fn =(pow((1 + sqrt(5))/2,nn)-pow((1-sqrt(5))/2, nn))/sqrt(5); return fn; } int FinalDigits(long double F){ if (F <= ..

Read more

int a1, a2, sum; cout<<"All the fibonacci numbert:"; for(int i=n; i>=a; i-=b){ a1=0; a2=1; /*if(i==0 || i==1){ cout<<setw(3)<<i; }*/ for(int y=i; y>0; y–){ sum=a1+a2; a1=a2; a2=sum; if(sum==i){ cout<<setw(3)<<sum; if(sum==1){ cout<<setw(3)<<a; } fibo+=i; } } } if(a==1){ fibo+=a; } cout<<"nthe Sum ist: "<<fibo<<endl; I have no idea what is happening from the first if statement. My ..

Read more