1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

C++ Program Enter number and print Fibonacci series upto that nth number

Discussion in 'C++' started by jeenu, Dec 18, 2013.

  1. jeenu

    jeenu Banned

    Joined:
    Dec 18, 2013
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi friends, would like to share something if Anyone wanted to know the C++ fibonacci program in simple way can go through this
    Code:
    // Program name : test051.c
    // Print Fibonica series of nth numbers
    #include <iostream.h>
    #include <conio.h>
    void main()
    {
    int n, first = 0, second = 1, third = 0;
    clrscr();
    cout <<"Enter Fibonica n th number : ";
    cin >> n;
    cout<<first<<" "<<second<<" ";
    for(int i = 3; i <= n; i++)
    {third = first + second;
    cout<<third<<" ";
    first = second;
    second = third;
    }
    getch();
    }
    Output
    Enter Fibonacci nth number : 10
    0 1 1 2 3 5 8 13 21 34

    Enter Fibonacci nth number : 15
    0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

    As i am a beginner,i am learning all programming languages in simple way with easy solutions.
     
    Last edited by a moderator: Dec 18, 2013

Share This Page