Fibonacci Series Program in C

In this section you will learn how to make Fibonacci series program using loop in C. Just simple mathematic operation we will perform to make the Fibonacci series program. In this program we are taking the input from user and assigning some default value to few variables.

Fibonacci Series Program

What is Fibonacci series or number?

A series of number in which each number is sum of previous two numbers. The Fibonacci series number is given below.

Example:

0, 1, 1, 2, 3, 5, 8, 13, upto n series.

0+1 =1, 1+1=2, 1+2=3, 3+5=8, 5+8=13.....

How program will work?

Program of fibonacci series in c.


	#include<stdio.h>
	#include<conio.h>
		
	//FIBONACCI SERIES PROGRAM
	void main()
	{
		int i=1, n;
		int f1 = 0, f2 = 1, f3;
		clrscr();

		printf("ENTER A NUMBER:- ");
		scanf("%d",&n);
		printf("%d %d ",f1,f2);
		do
		{
			f3=f1+f2;
			printf("%d ",f3);
			f1=f2;
			f2=f3;
			i++;
		}
		while(i<=n-1);

	getch();
	}
	

Output:


	ENTER A NUMBER:- 7
	0 1 1 2 3 5 8 13

Post Your Comment