Fibonacci Series using the recursive method
The following program prints the Fibonacci series.This program is implemented using recursive method. The Fibonacci series is a series of numbers in which the current number is the sum of two previous Fibonacci numbers. This program is coded using the C language.
Ex: 0,1,1,2,3,5,8,13....
Ex: 0,1,1,2,3,5,8,13....
#include<stdio.h>int main() { int n,i; printf("Enter the number of terms : "); scanf("%d",&n); printf("\nThe Fibonacci series is :\n"); for (i=0;i<=n;i++) printf("%d ", Fibonacci(i)); return 0; } int Fibonacci(int n) { if(n==0) return 0; else if(n==1) return 1; else return(Fibonacci(n-1)+Fibonacci(n-2)); }
Description:
The above program prints the number of terms in Fibonacci Series. Here n is the variable which is user input. It acts as a boundary limit for the generated Fibonacci Series. Output: Case 1: Enter the number of terms : 10 The Fibonacci series is : 0 1 1 2 3 5 8 13 21 34 Case 2: Enter the number of terms : 5 The Fibonacci series is : 0 1 1 2 3 Case 3: Enter the number of terms : 1 The Fibonacci series is : 0
Comments
Post a Comment