Skip to content
Utopper skill
  • ProgrammingExpand
    • Programming Examples
  • Interview QuestionsExpand
    • DevOps Interview Questions
    • Android Interview Questions
  • How to
  • Tools
  • Top 10
  • Book Summaries
Utopper skill
Programming Examples C Programming Example

Fibonacci Series in C

Article Contents

  1. Fibonacci Series in C
  2. What is Fibonacci Series?
  3. Approach to print Fibonacci Series in C Language
  4. Pseudo Code to Print Fibonacci Series in C Language
  5. C Program to print Fibonacci series
  6. The output will look something like this:

Fibonacci Series in C

The Fibonacci series in C is a sequence of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1.

What is Fibonacci Series?

The Fibonacci series is a sequence of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1.

The Fibonacci sequence is named after the Italian mathematician Leonardo of Pisa, who was also known as Fibonacci. He introduced the series to the Western mathematics in his book Liber Abaci, which he wrote in 1202.

The Fibonacci series is an example of a recursive sequence, which means that the next number in the series is calculated by adding the previous two numbers. The first few numbers in the series are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and so on. It is also closely related to the Golden Ratio and occurs in many natural phenomena, such as the branching of trees and the arrangement of leaves on a stem.

Approach to print Fibonacci Series in C Language

Here is one approach to print the Fibonacci series in C:

  1. Include the stdio.h header file to use the printf and scanf functions.
  2. In the main function, declare three variables: i, n, t1, t2, and nextTerm.
  3. Prompt the user to enter the number of terms they want in the series and store it in the variable n.
  4. Initialize t1 and t2 to 0 and 1 respectively. These will be the first two terms of the series.
  5. Use a for loop to iterate from 1 to n. In each iteration, print the value of t1, which is the current term in the series.
  6. Calculate the next term in the series by adding t1 and t2 and store it in the variable nextTerm.
  7. Update the values of t1 and t2 for the next iteration by setting t1 to the value of t2 and t2 to the value of nextTerm.
  8. Repeat steps 5 to 7 for all the iterations of the for loop.
  9. Finally, return 0 from the main function to indicate successful execution of the program.

This is just one of the possible approaches to print the Fibonacci series in C. There are many other ways to accomplish this task, each with its own advantages and disadvantages.

Pseudo Code to Print Fibonacci Series in C Language

// Pseudo code for printing Fibonacci series in C

// Step 1: Include the stdio.h header file
#include <stdio.h>

// Step 2: Define the main function
int main()
{
    // Step 3: Declare variables for iteration, number of terms, and the current and next terms in the series
    int i, n, t1, t2, nextTerm;

    // Step 4: Prompt the user to enter the number of terms they want in the series
    printf("Enter the number of terms: ");
    scanf("%d", &n);

    // Step 5: Initialize the first two terms in the series
    t1 = 0;
    t2 = 1;

    // Step 6: Use a for loop to iterate from 1 to the number of terms
    for(i = 1; i <= n; i++)
    {
        // Step 7: Print the current term in the series
        printf("%d ", t1);

        // Step 8: Calculate the next term in the series
        nextTerm = t1 + t2;

        // Step 9: Update the current and next terms for the next iteration
        t1 = t2;
        t2 = nextTerm;
    }

    // Step 10: Return 0 from the main function to indicate successful execution
    return 0;
}

C Program to print Fibonacci series

#include <stdio.h>

int main()
{
    int i, n, t1 = 0, t2 = 1, nextTerm;

    printf("Enter the number of terms: ");
    scanf("%d", &n);

    printf("Fibonacci Series: ");

    for (i = 1; i <= n; ++i)
    {
        printf("%d, ", t1);
        nextTerm = t1 + t2;
        t1 = t2;
        t2 = nextTerm;
    }

    return 0;
}

This C program will prompt the user to enter the number of terms they want in the Fibonacci series, and then print the series using a for loop. The initial values of t1 and t2 are set to 0 and 1 respectively, the same as the Fibonacci series. And with each iteration of the loop, the next term in the series is calculated and printed, and the values of t1 and t2 are updated for the next iteration.

The output will look something like this:

Enter the number of terms: 8
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13,

Please Remember that the exact output will depend on the value entered by the user for the number of terms.

Check Out Other Programs :

Palindrome Number in C
Post Tags: #C Program Examples#Fibonacci Series
Avatar photo
Utopper Skill Team
Facebook X Instagram YouTube Linkedin Pinterest

Post navigation

Previous Previous
Palindrome Number in C
NextContinue
Prime Number in C

Latest Interview Questions

  • C++ Program To Print Prime Numbers From 1 To N
  • C Program to Print Your Own Name with Example
  • Book Summary of Why We Sleep By Matthew Walker
  • Book Summary of Indistractable By Nir Eyal
  • C Program To Convert Fahrenheit To Celsius
  • Book Summary of The One Thing By Gary Keller and Jay Papasan
  • Facebook
  • Instagram
  • YouTube
  • Telegram
  • LinkedIn
  • Twitter

Mail : [email protected]

Privacy Policy | DISCLAIMER | Contact Us

Learn Development

learn HTML

learn CSS

learn JavaScript

Examples

C Examples

C++ Examples

Java Examples

Study Material

Interview Questions

How to

Hosting

SEO

Blogging

© 2023 Utopper.com

All Rights Reserved with Copyright & Registered TradeMarks
OWNED BY : GROWTH EDUCATION SOLUTIONS PRIVATE LIMITED

Scroll to top
  • Programming
    • Programming Examples
  • Interview Questions
    • DevOps Interview Questions
    • Android Interview Questions
  • How to
  • Tools
  • Top 10
  • Book Summaries
Search