simply we are using the concept Fn = Fn-1 + Fn-2 .
#include<stdio.h>
int Fibonacci(int n)
{
int f0 = 0, f1 = 1, f =0, i=0;
if( n == 0)
return f0;
for (i = 2; i <= n; i++)
{
f = f0 + f1;
f0 = f1;
f1 = f;
}
return f1;
}
int main ()
{
int n = 0;
int fn = 0;
printf("\n Enter Number to find nth Fibonacci Number = ");
scanf("%d", &n);
if(n < 0)
{
printf("Please Enter Positive number\n\n");
return -1;
}
fn = Fibonacci(n);
printf("\n %d Fibonacci Number = %d\n\n", n, fn);
return 0;
}
simply we are using the concept Fn = Fn-1 + Fn-2 .
need an explanation for this answer? contact us directly to get an explanation for this answer