Powered by Blogger.

Fibonacci Series C++



Fibonacci Series C++


To print fibonacci series add two previous term and get next term, this process follow until your requirment complete. Fibonacci Series C++

Fibonacci Series C++

#include <iostream>
using namespace std;
int main()
{
    int num1 = 0;
    int num2 = 1;
    int num_temp;
    int num_next = 1;
    int n;
    cin >> n;
    if (n>=1)
        cout << num1 << " ";
    if (n>=2)
        cout << num2 << " ";
    for (int i = 0; i < n-2; i++)
{
        num_next = num1 + num2;
        cout << num_next << " ";
        num1 = num2;
        num2 = num_next;
    }
    cout << endl;
    return 0;
}

Output:

0 1 1 2 3 5 8



facebook
google-plus
twitter
pinterest

No comments :

Post a Comment

HTML Tutorial

images

About Sitesbay

This blog is related to Java Tutorial, C++ Tutorial, C Tutorial, Online Earning tips and more in very simple and easy way. Here i will try to give complete idea related to all new technology.

Java Tutorial

Java is Object oriented programming language, It is more secure and high performance language.

C++ Tutorial

C++ is also Object oriented programming language, It is more simple and easy to learn.

 
https://sitesbay.blogspot.com/?utm_medium=d2898efa59afcc0bc411921036e22b767ca37b09