Skip to content

Commit 94f34b5

Browse files
authored
Create Fibonacci USing Recursion.c
1 parent 28316c1 commit 94f34b5

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Fibonacci USing Recursion.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <stdio.h>
2+
int fibo(int);
3+
int main()
4+
{
5+
int num;
6+
int result;
7+
printf("Enter the nth number in fibonacci series: ");
8+
scanf("%d", &num);
9+
if (num < 0)
10+
{
11+
printf("Fibonacci of negative number is not possible.\n");
12+
}
13+
else
14+
{
15+
result = fibo(num);
16+
printf("The %d number in fibonacci series is %d\n", num, result);
17+
}
18+
return 0;
19+
}
20+
int fibo(int num)
21+
{
22+
if (num == 0)
23+
{
24+
return 0;
25+
}
26+
else if (num == 1)
27+
{
28+
return 1;
29+
}
30+
else
31+
{
32+
return(fibo(num - 1) + fibo(num - 2));
33+
}
34+
}

0 commit comments

Comments
 (0)