Using this program a user can find a fibonacci series of entered number, so first let us understand what is Fibonacci Series. Numbers in Fibonacci Series are known as Fibonacci numbers. It is a series of number having particular pattern. For example first few numbers are:- 0,1,1,2,3,5,8,13,21...
Except first two numbers other numbers are found by adding previous two numbers. Ex: 2 is found by adding previous two numbers (1+1). see the program and observe the output, you will understand what exactly Fibonacci Series is.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int c,n,t1=0,t2=1,display;
printf("Enter a number\n");
scanf("%d",&n);
printf("Fibonaci series:\n",n);
for(c=0;c<n;c++)
{
if(c<=1)
display=c;
else
{
display=t1+t2;
t1=t2;
t2=display;
}
printf("%d\n",display);
}
getch();
}
Output:
This is the output you will get if you run the above given program to find Fibonacci Series using For Loop.
No comments:
Post a Comment
Feel free to ask us any question regarding this post