Fibonacci Sequence ID:2568


An integer value N is passed as the input. The program must print the first N terms in the Fibonacci sequence.


Input Format:

The first line denotes the value of N.


Output Format:

The first N terms in the Fibonacci sequence (with each term separated by a space)


Boundary Conditions:

3 <= N <= 50


Example Input/Output 1:

Input:

5


Output:

0 1 1 2 3


Example Input/Output 2:

Input:

10


Output:

0 1 1 2 3 5 8 13 21 34

PROGRAM IN C:

 #include <stdio.h>

#include <stdlib.h>


int main()

{

    long int N;

    scanf("%ld",&N);

    long int term1=0,term2=1;

    printf("%ld %ld",term1,term2);

    for(int ctr = 1; ctr <= N-2; ctr++)

    {

        long int curr = term1 + term2;

        printf(" %ld", curr);

        term1 = term2;

        term2 = curr;

    }

    return 0;

}

Comments

Popular Posts