fibonaci number - My articles - Publisher - Information Technology
Sunday, 2016-12-04, 5:14 PM
ebooks Programming Computer Science
Welcome Guest | RSS
Site menu
Section categories
My articles [23]
Main » Articles » My articles

fibonaci number
#include<stdio.h>

int fib(int);

int fib_friz[60];

int main()
{
int num;
printf("Enter a number: ");
scanf("%d",&num);

for(int i = 0; i < 60; i++)
fib_friz[i] = -1;

printf("%d\n",fib(num));
    
return 0;
}

int fib(int n)
{
if(n==0)
return 1;
if(n==1)
return 1;
if(fib_friz[n] > -1)
return fib_friz[n];

int result = fib(n-1)+fib(n-2);
fib_friz[n] = result;
return result;
}
Category: My articles | Added by: Sumrat (2012-02-22)
Views: 281 | Rating: 0.0/0
Total comments: 0
Name *:
Email *:
Code *:
Our poll
Rate my site
Total of answers: 152
Statistics

Total online: 1
Guests: 1
Users: 0
Login form