Ex.No:7b Fibonacci number Using Recursion
AIM:
To write a program to find the ith Fibonacci number using recursion, given F(0)=0, F(1)=1.
ALGORITHM:
Step 1: Start the program
Step 2: read num
Step 3: f <- fibo(num)
Step 4: print f
Step 5: Stop
Step 1: fibo start
Step 2: If n<=1
Return 1
Else
Return fibo(n-1)+fibo(n-2)
PROGRAM CODE:
#include<stdio.h> #include<conio.h> void main() { int num,a; printf("nEnter the number"); scanf("%d",&num); a=fibo(num); printf("nThe fibonacci of the number %d is %d",num,a); getch(); } int fibo(int n) { if(n==0) return(0); if(n==1) return(1); else return fibo(n-1)+fibo(n-2); }
OUTPUT:
RESULT:
Thus the C program to find the ith Fibonacci number using recursion is written and executed successfully.