Write a program to print the Fibonacci series with a given number in C language.

Tested on: Turbo C++ Version 4.0Time Complexity: O (2n)Space Complexity: O (n)Open Source: MIT
1
2
    #include <stdio.h>
3
    #include <conio.h>
4
    int fabin(int n)
5
    {
6
        if (n == 1)
7
            return 0;
8
        if (n == 2)
9
            return 1;
10
        else
11
            return fabin(n - 1) + fabin(n - 2);
12
    }
13
    void main()
14
    {
15
        int a = 0, b = 1, n, i;
16
        clrscr();
17
        printf("Enter the No. of terms: ");
18
        scanf("%d", &n);
19
        printf("%d terms of fibonacci series is ", n);
20
        printf("\n %d \t %d\t", a, b);
21
        for (i = 3; i <= n; i++)
22
            printf("%d\t", fabin(i));
23
    }
24
25
        

Output

1
2
    Enter the No. of terms: 10
3
    10 terms of fibonacci series is 
4
     0 	 1	1	2	3	5	8	13	21	34	
5
   
6
   

Rate the Code

Reviews are published after a quick safety check (usually within 24 hours).

Reviews are public. Developers can see basic device specifications to respond. Learn more

How to run print the Fibonacci series program in C-Language?

To run print the Fibonacci series program in C-Language, follow the below mentioned steps:

  1. Copy the Code: Press the copy button in the code block to copy the complete code.
  2. Open Turbo C++ Version 4: Open the Turbo C++ (Version 4) software on your system.
  3. Paste the code: Paste the copied code into Turbo C++’s editor.
  4. Compile the Code: Compile the program by pressing the Alt+F9 keys. This shows you the errors and warnings, if any.
  5. Run the code: Press the Ctrl+F9 keys to run the program if the program is successfully compiled.
  6. Enter the Input: Provide the required inputs or your desired inputs, if applicable.
  7. Receive the Result: Get the result of the program on the screen based on the provided inputs.

More about the Fibonacci Series program in the C language

Aim: to print out the Fibonacci series up to user given terms value. For example, if the user enters 5, then the output will be               0            1            1            2            3

Concepts used in this program

  • Recursion: A function calling itself to calculate the Fibonacci number
  • Base condition: The return 0 value for n==1 & return 1 value for n==2, where n is the terms of Fibonacci series.
  • Recursive relation: The sum of the last two numbers is calculated to make the next number.
  • For Loop: To print the result, all the numbers are traversed.

Real-Life applications

  • Fibonacci Heap (Data Structure): This is an advanced Data structure that is used to perform priority queue operations. Also used in graph algorithms.
  • Fibonacci Search Algorithm: Used to find an element in a stored array.
License: This program's source code is open-sourced under the MIT License, while the rest of the program's text content and overall dhimanp platform and brand content remain proprietary under dhimanp.

Submit your modified code

Your submissions are published after a quick safety check (usually within 7 days).

Submissions are public. Developers can see basic device specifications to respond. Learn more

Disclaimer

The information that you shared with us will be publicly visible, and everyone can see your information. And we (dhimanp) are not responsible if anyone misuses this information. We can remove any submitted code at any time for better transparency.

Privacy Policy

If you share your data with us by submitting your code for credit, then we may show your full name, school or college name, and city name on our website.

We are not using this data to track you and are not selling this data to anyone.

If you want to remove your name from our website, you can contact us, and we will remove your name from our website. In the removal process, full credit, including your full name, school or college, city, and code, will be removed from our website.