pages

Wednesday, 14 April 2021

c-program to display Fibonacci series.| c-programming

C-Program to  print Fibonacci series .

Fibonacci series is a sequence of number where the next is the sum of the previous two terms . 

for example:- 0,1,1,2,,3,5,8,13,21,34,55 etc. The first two numbers of Fibonacci series are 0 and 1.

A simple For loop is used to display the series. Taking input from the user for the number of terms to display . 



#include<stdio.h>
#include<conio.h>
void main()
{
   int n,i,a=-1,b=1,c=0;
   printf("enter the number\n");
   scanf("%d",&n);
   for(i=0;i<n;i++){
         c=a+b;
         printf("%d ",c);
         a=b;
         b=c;
   }
   getch();
}

output:  






















No comments:

Post a Comment