Program to find the Fibonacci Series

0 Suresh Chand June 2, 2021

In this example, We will learn a program to find the Fibonacci Series. Before that, You must have knowledge of the following topics

Algorithm

This is the algorithm of program to find fibonacci Series

Step 1: Start

Step 2: Initialize variables i, n, t1 = 0, t2 = 1

Step 3: Initialize variable and assign t1 + t2

Step 4: Take input from the user and assign to variable n

Step 5: Assign i = 1

Step 6: Repeat this step until i <= n

           Step 6.1: Print nextTerm variable

          Step 6.2: t1 = t2

         Step 6.3: t2 = nextTerm

         Step 6.4: nextTerm = t1 + t2

Step 7: End

Flowchart

This is the flowchart of program to find fibonacci Series

Flowchart : Program to find the Fibonacci Series

CODE: Program to find the fibonacci Series

We will print fibonacci Series using for loop.

#include <stdio.h>

int main() {

    int i, n, t1 = 0, t2 = 1;
    int nextTerm = t1 + t2;
    
    printf("Enter the number of terms: ");
    scanf("%d", &n);
    printf("Fibonacci Series: %d\t%d\t", t1, t2);

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

    return 0;
}

Download Application: Learn C Programming with Live Compiler

The output of above program is

Enter number of terms : 10
0       1       1       2       3       5       8       13      21      34
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Join Our Newsletter Now

Get the latest tutorials, examples and projects updates.

Ads Block Detector Powered by codehelppro.com

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Disable Ad Block

Want Same System