Fibonacci series in c language
Fibonacci series in c language
Fibonacci series is series of number in which any number is sum of it's preceding two number.This blog will introduce you to the concept of how to write program to print Fibonacci series in c language.
Example of Fibonacci series: 0 1 1 2 3 5 8 13 ...................
Following method has used in program
- First two term of Fibonacci series is constant.
- Take two constant term .
- Ask user up to what limit he want to print Fibonacci series.
- Run the iteration till the last term of Fibonacci term.
- Then apply the condition to print Fibonacci series inside iteration.
- Print the Fibonacci series.
Printing Fibonacci series in c language.
The following code has run in turbo compiler.I personally use turbo editor for
writing my c language program.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int fib1=0,fib2=1,fib3,count=0,limit;
printf("Enter limit\n");
scanf("%d",&limit);
printf("%d",fib1);
printf("%d",fib2);
count=2;
while(count<limit)
{
fib3=fib1+fib2;
printf("%d",fib3);
fib1=fib2;
fib2=fib3;
count++;
}
getch();
}
Fibonacci series in c language
Reviewed by Deepak kumar soni
on
December 29, 2018
Rating:
No comments: