• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Lab » Fibonacci Series in C
Next →
← Prev

What is Fibonacci Series in C with Example?

By Dinesh Thakur

In this tutorial, We will learn Fibonacci Series in C programming language. Fibonacci Series generates the next number by adding two last numbers.

We’ll be covering the following topics in this tutorial:

  • What is Fibonacci Series in C?
  • Algorithm of Fibonacci Series
  • Pseudocode of Fibonacci series
  • Fibonacci Series C Programs

What is Fibonacci Series in C?

Fibonacci Series in C: The Fibonacci Sequence is the sequence of numbers where the next term is the sum of the previous two terms. The first two terms in the Fibonacci series are 0, accompanied by 1. The Fibonacci sequence: 0 , 1, 1, 2, 3, 5, 8, 13, 21.

Algorithm of Fibonacci Series

START
Step 1 → Enter int variable A, B, C
Step 2 → Set A = 0, B = 0
Step 3 → DISPLAY A, B
Step 4 → C = A + B
Step 5 → DISPLAY C
Step 6 → Set A = B, B = C
Step 7 → REPEAT from 4 - 6, for n times
STOP

Pseudocode of Fibonacci series

procedure fibonacci : fibonacci_number

  IF fibonacci_number less than 1
     DISPLAY 0
  IF fibonacci_number equals to 1
     DISPLAY 1
  IF fibonacci_number equals to 2
     DISPLAY 1, 1
  IF fibonacci_number greater than 2
     Pre = 1,
     Post = 1,
     DISPLAY Pre, Post
     FOR 0 to fibonacci_number-2
        Fib = Pre + Post
        DISPLAY Fib
        Pre = Post
        Post = Fib
    END FOR
END IF
end procedure

Fibonacci Series C Programs

Let us denote ith term in the Fibonacci series as Fi, where i is assumed to take values starting from 0. Thus, the first four terms in the Fibonacci series are denoted as F0, F1, F2. and F3. The first two terms are given as F0 = 0 and F1 = 1.
Each subsequent term is obtained by adding two previous terms in the series. Thus, the first 10 terms in the series are 0, 1, 1, 2, 3, 5, 8, 13, 21, and 34. The equation for term Fi, i > 2, can be expressed in the form of a recurrence relationship as Fi = Fi -1+ Fi – 2.
Let us use the variable term to represent term Fi in the Fibonacci series and variables prev1 and prev2 to define previous terms (Fi-1 and Fi-2) as shown in the prev2 prev1 term for i = 2. Now the F2 can be obtained as

term = prev1 + prev2;

To determine the next term in the series, first move prev1 and prev2 to next position as shown in using the following statements:

prev2 = prev1;
prev1 = term;

Now term F3 can be calculated using the same statement given above (term = prev1 + prev2). We can determine the subsequent terms in the series by repeating the above procedure. A program to determine and print the first n terms in the Fibonacci series is given below.

#include<stdio.h>
int old_number;
int current_number;
int next_number;
int main() {
 old_number = 1;
 current_number = 1;
 clrscr();
 printf("Fibonacci Series are : \n");
 printf("1 ");
 while (current_number<100) {
 printf(" %d ", current_number);
 next_number = current_number + old_number;
 old_number = current_number;
 current_number = next_number;
}
 getch();
 return (0);
}

Fibonacci Series

Fibonacci Series Program in C Using for Loop

/* Fibonacci Series c language */

#include<stdio.h>
void main() {
  int n, first = 0, second = 1, next, c;
  clrscr();
  printf("Enter the Number of Terms : ");
  scanf("%d",&n);
  printf("First %d terms of Fibonacci Series are : ",n);
  for (c = 0;c < n;c++) {
    if ( c <= 1 )
      next = c;
    else {
       next = first + second;
       first = second;
       second = next;
    }
    printf(" %d ",next);
  }
   getch();
}

Fibonacci Series c language

Fibonacci Series Using Recursion in C

#include<stdio.h>
int fib(int m);
void main() {
 int i,n;
 clrscr();
 printf("\n Enter no: of Terms = ");
 scanf("%d",&n);
 for(i = 1;i <= n;i++) {
    printf(" %d ",fib(i));
 }
  getch();
}
int fib(int m) {
  if(m == 1 || m == 2) {
     return(1);
  }
  else {
    return(fib(m-1)+ fib(m-2));
  }
}

Fibonacci Series Using Recursion

Explanation: In this program, recursion is used because the Fibonacci number n is generated to the sum of its last number

fib (m) = fib (m-1) + fib (m-2)

Here fib () is a function that computes nth Fibonacci number. The exit criteria are that if m==1 then return 0 and if the exit criteria are m==2, then return 1.

C Program to print Fibonacci Series upto N number

#include<stdio.h>
#include<conio.h>
void main() {
  int a=0, b=1, c, n, count;
  printf("How many fibonacci numbers :");
  scanf ("%d", &n);
  if (n==1)
    printf ( "0");
  else if (n==2)
    printf ( "1" ) ;
  else {
    printf ("%d\t%d" ,a,b);
    count=3;
  while(count<=n) {
    c = a+b;
    printf ( "\t%d", c);
    a = b;
    b = c;
    count++;
  }
}
  getch();
}

Fibonacci Series upto N number

Explanation: On execution, the user is prompted to enter the number of terms Fibonacci series (n = say 12) that need to be printed. As n = 12, so the expression if (n==0) evaluates to false,and the control shifts to else if part. As the expression if(n==1) also evaluates to false, the control shifts to the next part.
The statements in its body are executed. First, the first two Fibonacci numbers are printed. Then we set count=3. Now, as we have to print first n Fibonacci numbers, so we take a while loop as shown.
We know that,

Fibonacci (n) = fibonacci(n-1) + fibonacci(n-2)

Therefore, we go on adding the previous numbers and print the result. To proceed, we assign the value stored in b to a, and the value of c is assigned to b. The value of count is incremented by 1 on each such operation. The process continues until the condition remains satisfied.

You’ll also like:

  1. Fibonacci Series in Java Example
  2. Fibonacci Series in Python
  3. Fibonacci Series Using Recursion in Java Example
  4. Write A C++ Program To Display Fibonacci Using Recursion.
  5. C Program Write a Program For Sine Series
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

C Programming

C Programming Tutorials

  • C - History
  • C - Anatomy
  • C - Constants
  • C - Identifiers
  • C - Data Types
  • C - Libraries File
  • C - Header Files
  • C - Basic Language
  • C - Data Types Sizes
  • C - Header Files Importance
  • C - Escape Sequences
  • C - Main() Purpose
  • C - Program Procedure
  • C - Control Statements
  • C - Enumeration Constant
  • C - Add numbers
  • C - Return Statement
  • C - Avoid Goto
  • C - Command Line Arguments
  • C - Switch Case
  • C - Switch Case Limitations
  • C - getchar() and putchar()
  • C - Iteration Statements
  • C - Pass by Value and Reference
  • C - Structures and Unions
  • C - Structure
  • C - Dynamic Memory
  • C - Fgets and Fputs Functions
  • C - Gets() and Puts() Functions
  • C - Armstrong Number
  • C - Storage Classes
  • C - Fibonacci Series
  • C - Precision Setting
  • C - const Parameters

C - Variable & It's Type

  • C - Variables
  • C - Variable Lifetime
  • C - Static Variable
  • C - Register Variable
  • C - Global Variables
  • C - Auto Variables
  • C - Local Variables

C - Operator & Expressions

  • C - Operator
  • C - Boolean Operators
  • C - Bitwise Operator
  • C - Arithmetic Operators
  • C - Modulus Operator
  • C - Ternary Operator
  • C - Expressions
  • C - Arithmetic Expressions

C - Array

  • C - Arrays
  • C - Array Types
  • C - Array Characteristics
  • C - Static Arrays
  • C - Global Arrays
  • C - 3D Arrays
  • C - Dynamic Arrays
  • C - Pointer to 3D Arrays
  • C - Array Elements Hold
  • C - Arrays as Function Parameters
  • C - Accessing Matrix Elements
  • C - File Handling
  • C - Matrix Multiplication
  • C - Dynamic Memory Allocation

C - Searching & Sorting

  • C - Data Structures
  • C - Linear Search
  • C - Bubble Sort
  • C - Merge Sort
  • C - Linked List
  • C - Insertion Sort
  • C - Binary Search
  • C - Selection Sort
  • C - Quick Sort

C - Functions

  • C - Functions
  • C - Functions Advantages
  • C - Void Functions
  • C - Function Call
  • C - Default Return Value
  • C - String functions

C - Pointer

  • C - Pointers
  • C - Type Casting Of Pointers
  • C - Pointer Advantages
  • C - Pointers Initialization
  • C - Vectors and Pointers

C - Differences

  • C - C Vs C++
  • C - Formal Args. Vs Actual Args.
  • C - Keywords Vs Identifiers
  • C - Strings Vs Character Arrays
  • C - Address Vs Dereference Operator
  • C - Goto Vs longjmp
  • C - Declaring Vs Defining Variable
  • C - String Vs Array
  • C - Call by Value Vs Reference
  • C - Structure Vs Union
  • C - For Vs While loops
  • C - Compiler Vs Interpreter

C - Programs

  • C Program Standard Deviation
  • C Program Calculate Tax
  • C Program Sum Series
  • C Program Merge Arrays
  • C Program Euclid’s Algorithm
  • C Program Print Weekdays
  • C Program Sum of Digits
  • C Program Print a list
  • C Program Print Pythagorean
  • C Program Quiz program
  • C Program Display Table
  • C Program Print Comma-Separated
  • C Program Prints Prime Numbers
  • C Program for Print Integer
  • C Program Count Number
  • C Program Print Color Name
  • C Program Print Odd Numbers
  • C Program Calculate area
  • C Program for a Menu
  • C Program Add Two Vectors
  • C Program Array Addresses
  • C Program Division by Zero Error
  • C Program Compare two Dates
  • C Program Tower of Hanoi
  • C Program return 3 Numbers
  • C Program for Prime Numbers
  • C Program for Factorial
  • C Program for Palindrome

Other Links

  • C Programming - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW