print the Fibonacci series from user input.


Fibonacci series  

a series of numbers in which each number (Fibonacci number) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, etc. 

QUESTION:- print the Fibonacci series from user input. 


#include <stdio.h>

#include <conio.h>

void main()

{

    int first = 0, second = 1, next, no;

    printf("enter a value: ");

    scanf("%d", &no);

    for (int i = 0; i <= no; i++)

    {

        if (i <= 1)

        {

            next = i;
        }

        else

        {

            next = first + second;

            first = second;

            second = next;

            printf("%d  ", next);
        }
    }

    getch();
}

OUTPUT
enter a value: 10
1  2  3  5  8  13  21  34  55  

Follow our page for regular updates.

0 Comments