C program to display Fibonacci series - My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Thursday, November 28, 2019

C program to display Fibonacci series - My CS Tutorial

Fibonacci series example
In this tutorial we will learn how to write a program that display Fibonacci series.This program will accept a number and print Fibonacci series according to this number.

For ex.-

We will enter a number as 9 and the Fibonacci series is





C PROGRAM CODE


#include<stdio.h>
#include<conio.h>
void main()
{
 int a=0,b=1,num,c,count;
 printf("\n Enter a number to obtain fibonacci series:\n ");
 scanf("%d",&num);
 printf("\n The series is:\n ");
 printf("%d\n %d\n ",a,b);
 count=2;
 while(count<num)
     {
       c=a+b;
       a=b;
       b=c;
       printf("%d\n ",c);
       count++;
     }
     getch();
    }


OUTPUT 1:






OUTPUT 2:







In first output,the value of number is 8

And the series is...

0, 1, 1, 2, 3, 5, 8, 13


In second output,the value of number is 8

And the series is...

0, 1, 1, 2, 3, 5, 8, 13, 21, 34



Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.

Created by-- HARSH CHAUHAN

No comments:

Post a Comment