Fibonacci Series

Fibonacci series is a series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers.

e.g. 0, 1, 1, 2, 3, 5, 8, etc.

The Rule is to write a Fibonacci series is: xn = xn−1 + xn−2

where:

  • xn is term number “n”
  • xn−1 is the previous term (n−1)
  • xn−2 is the term before that (n−2)
#include <stdio.h>

void fibo(int a, int b, int sum, int num)
{

	if (num != 0) {

		printf(" %d", a);
		sum = a + b;
		a = b;
		b = sum;

		num--;

		fibo(a, b, sum, num);
	}
}
int main()
{

	int num;
	printf("Enter the number: ");
	scanf("%d",&num);

	fibo(0, 1, 0, num);
	return 0;
}

Leave a comment

Create a website or blog at WordPress.com

Up ↑

Design a site like this with WordPress.com
Get started