WAP in C to find the nth number in Fibonacci series using recursion?

#include <stdio.h>
#include<conio.h>
int fibo(int);
int main()
{
int num, result;
printf(“Enter the nth number in fibonacci series: “);
scanf(“%d”, &num);
if (num < 0)
{
printf(“Fibonacci of negative number is not possible.\n”);
}
else
{
result = fibo(num);
printf(“The %d number in fibonacci series is %d\n”, num, result);
}
getch();
return(0);
}
int fibo(int num)
{
if (num == 0)
{
return(0);
}
else if (num == 1)
{
return(1);
}
else
{
return(fibo(num – 1) + fibo(num – 2));
}
}

Output:-

fabirecu.png

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s