#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
#define tip long
tip z;
tip Fibonacci(tip n ){
tip i = 1, j = 0, k = 0, h = 1, t = 0;
while( n > 0 )
{
z++;
if( ((long) n) % 2 )
{
t = j * h;
j = i * h + j * k + t;
i = i * k + t;
}
t = h * h;
h = 2 * k * h + t;
k = k * k + t;
n = n / 2;
}
return j;
}
int main()
{
z = 0;
cout << "\n\n\n 5th = " << Fibonacci( 5 );
cout << "\n Nr. of iterations = " << z;
z = 0;
cout << "\n\n 10th = " << Fibonacci( 10 );
cout << "\n Nr. of iterations = " << z;
z = 0;
cout << "\n\n 20th = " << Fibonacci( 20 );
cout << "\n Nr. of iterations = " << z;
z = 0;
cout << "\n\n 40th = " << Fibonacci( 40 );
cout << "\n Nr of iterations = " << z;
cout << "\n\n";
return 0;
}
I have this program just like that. Without comments, variables with meaningless names.
The program is working. No errors, or something else. It just shows the number value and number of iterations.
Questions :
I don't understand what those variables ( *i, j, k, h, t* )
mean?
What they do in this algorithm?
What algorithm is this?