#include<math.h>
#include<conio.h>
#include<stdio.h>
int fib(int n)
{
if(n==0||n==1){
return n;
}else
{
int const a=fib((n+1)/2);
int const b=fib((n+1)/2-1);
if(n%2==0){
return a*(a+2*b);
}else{
return a*a+b*b;
}
}
}
void main()
{
int x;
for(x=1; x<7; ++x)
{
printf("Fibonacci [%d] = %d \n",x,fib(x));
}
getch();
}
Tuesday, April 27, 2010
Contoh Script Rekusi c++
Posted by Gh0St at 5:14 AM
Labels: source code c++ |
0 Comments:
Post a Comment