Thursday, September 13, 2018

FIBONACCI SERIES

  • Problem Description

    An interesting sequence which contains a series of numbers in which each sequent number is the sum of its two previous numbers which is also called as fibonacci sequence.Write a program to generate Fibonacci sequence.

    Input:
    Enter the limit for generating Fibonacci sequence.

    Output:
    Display the Fibonacci sequence till the limit.
  • CODING ARENA
  • #include <stdio.h>
    int main()
    {
      int i,n,t1=0,t2=1,nxt;
      scanf("%d",&n);
      for(i=1;i<=n;++i)
      {
        printf("%d ",t1);
        nxt=t1+t2;
        t1=t2;
        t2=nxt;
      }
      

    return 0;
    }
  • Test Case 1

    Input (stdin)
    5
    
    
    Expected Output
    0 1 1 2 3
  • Test Case 2

    Input (stdin)
    6
    
    
    Expected Output
    0 1 1 2 3 5

No comments:

Post a Comment