C Program to Find Nth Fibonacci Number Using Recursion

include

int fib (int);
int main ()
{
int n, result;
printf (“Enter the Nth Number: “);
scanf (“%d”, &n);
result = fib (n);
printf (“The %dth number in Fibonacci series is %d\n”, n, result);
return 0;
}

/* function for recursive fibonocci call */
int fib (int n)
{
if (n == 0)
{
return 0;
}
else if (n == 1)
{
return 1;
}
else
{
return (fib (n – 1) + fib (n – 2));
}
}

OUTPUT:

Enter the Nth Number: 8
The 8th number in Fibonacci series is 21

Leave a Reply

Your email address will not be published.