Back to Basics : Fibonacci Series
- In the 12th century, Leonardo Fibonacci discovered a simple numerical series Called Fibonacci Series.
- Starting with 0 and 1, each new number in the series is simply the sum of the two before it.
- To watch more about Fibonacci series - It will Explain everything about this series.
C Program to print Fibonacci Series using recursion !!
#include<stdio.h> #include<conio.h> int size; int fibonacci (int prev_number, int number); void main() { static int prev_number=0,number=1; clrscr(); printf("Enter the Size of Series (< 20) : "); scanf("%d",&size); printf("1 "); fibonacci (prev_number,number); getch(); } int fibonacci (int prev_number, int number) { static int i=1; int next_num; if (i==size) return(0); else { next_num=prev_number+number; prev_number=number; number=next_num; printf ("%d ",next_num); i++; // increment counter fibonacci (prev_number,number); //recursion } return(0); }
Output :
Enter the Size of Series (< 20) : 6 1 1 2 3 5 8 13
No comments:
Post a Comment