Write a program to generate Fibonacci series. The user enter the limit of series.
This post contains a program in c that program will generate the Fibonacci series. The limit of Fibonacci series element will be entered by user. as we know the Fibonacci series is the sum of the two preceding number of the series .
i.e. 1, 1, 2, 3, 5, 8, 13, 21, ........known as Fibonacci series.
Now see the program:
#include<stdio.h>#include<conio.h>void fiboseries(int);int main(){int limit,first = 0,second = 1;printf("Enter the limit of Fibonacci series\t");scanf("%d",&limit);
if(limit > 2){printf("%d\t%d",first,second);fiboseries(limit - 2);}else if(limit == 2){printf(" %d\t%d",first,second);}else if(limit == 1){printf("\t%d",second);}else{printf("\nSeries not possible");}}void fiboseries(int x){int fibo;static int first = 0,second = 1;if(x == 0){printf("\nSeries displayed above");}else{fibo = first + second;first = second;second = fibo;printf("\t%d",fibo);fiboseries(x-1);}}
Output:
Enter the limit of Fibonacci series 5
1
1
2
3
5
Series displayed above
Do not forget to subscribe me for latest update on my blog , follow me and grow your knowledge. thank you
0 comments:
Post a Comment