C Program to Generate and Print Fibonacci series upto a given inputted number
In this example, we will generate and print fibonacci series upto a the upper limit entered by the user. To solve this problem we should have a proper concept on Fibonacci series and while loop.
What is a Fibonacci Series?
Fibonacci series is the sum of the two preceding numbers, starting from 0 and 1.
For Example: 0,1,1,2,3,5,8,13,....,etc
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int n,x1,x2,x3=0;
printf("Enter the limit upto which fibonacci series to be generated : ");
scanf("%d",&n);
x1=0;
x2=1;
printf("%d\t%d",x1,x2);
x3=x1+x2;
while(x3<=n)
{
printf("\t%d",x3);
x1=x2;
x2=x3;
x3=x1+x2;
}
getch();
}
OUTPUT:
Enter the limit upto which fibonacci series to be generated : 30
0 1 1 2 3 5 8 13 21
NOTE: You Can Comment Your Code if you have solved differently and we will pin it in the comment section. Let's Learn together.
MOTTO:
You Learn, I Learn together We Learn.
Comments
Post a Comment
Please do not spam any link