C Program to Display Fibonacci Series

Last Updated:

What is Fibonacci Series?

A series of numbers in which each number (Fibonacci number) is the sum of the two preceding numbers, starting from 0 and 1, i.e., 0, 1, 1, 2, 3, 5, 8, 13, 21, and so on.

Tips: It is recommended to use our online Fibonacci Series calculator for better understanding.

Fibonacci Series between the Given Limit

In the following example, we will find the Fibonacci Series between 0 and 100.

Example

C Compiler
#include <stdio.h> int main() { int limit = 100; int a = 0; int b = 1; int c = 0; printf("Fibonacci series upto %d: \n", limit); printf("%d %d", a, b); while(c <= limit) { c = a + b; a = b; b = c; if(c <= limit) printf(" %d", c); } return 0; }

Fibonacci Series between any given Limit

In the following example, we will display the fibonacci series from 0 to any given limit.

Example

C Compiler
#include <stdio.h> int main() { int limit; int a = 0; int b = 1; int c = 0; printf("Enter a (int) limit: "); scanf("%d", &limit); printf("\nFibonacci series upto %d: \n", limit); printf("%d %d", a, b); while(c <= limit) { c = a + b; a = b; b = c; if(c <= limit) printf(" %d", c); } return 0; }

Share this Page

Meet the Author