DOTCPPH.BLOGSPOT.COM

CPP GUI Source Code
+ Getting start with Visual Studio C++ CLR GUI applications
+ Get the size of a File using C++
+ How use C++ to get the Size of Files in a Directory
+ Read and Write .ini Files by Using C++
+ Use of C++ to Delete a File
+ Explain how to Delete Multiple Files Using C++
+ Use of C++ Shell Execute to Open programs

If you would like the navigation along the top, simply move the ul.nav to the top of the page and recreate the styling.

(function() { var useSSL = 'https:' == document.location.protocol; var src = (useSSL ? 'https:' : 'http:') + '//www.googletagservices.com/tag/js/gpt.js'; document.write(''); })(); googletag.cmd.push(function() { googletag.defineSlot('/32882001/L', [728, 90], 'div-gpt-ad-1473193443042-0').addService(googletag.pubads()); googletag.pubads().enableSingleRequest(); googletag.pubads().enableSyncRendering(); googletag.enableServices(); });
  • Articles
  • C++ class for generate Fibonacci series
Published by
Aug 9, 2016 (last update: Aug 9, 2016)

C++ class for generate Fibonacci series

Score: 3.3/5 (101 votes)
*****

Fibonacci class

The Fibonacci sequence is named after italian mathematician Leonardo of Pisa, known as Fibonacci. His 1202 book "Liber Abaci" introduced the sequence to Western European mathematics, althoutgh the sequence had been described earlier as Virahanka numbers in Indian mathematics. By convention, the sequence begin either with Fo=0 or with F1=1.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>

using namespace std;

class Fibonacci{
public:
    int a, b, c;
    void generate(int);
};

void Fibonacci::generate(int n){
    a = 0; b = 1;
    cout << a << " " <<b;
    for(int i=1; i<= n-2; i++){
        c = a + b;
        cout << " " << c;
        a = b;
        b = c;
    }
}

int main()
{
    cout << "Hello world! Fibonacci series" << endl;
    cout << "Enter number of items you need in the series: ";
    int n;
    cin  >> n;
    Fibonacci fibonacci;
    fibonacci.generate(n);
    return 0;
}

Attachments: [main.cpp]

<-- type="text/java--" <--> (function(){ // mini cookie-consent code (c) Juan Soulie, 2016 var s ='consent=cookie'; var e = document.createElement('div'); e.innerHTML = '
This website uses cookies. By continuing, you give permission to deploy cookies, as detailed in our privacy policy. ok
'; if (document.cookie.indexOf(s)!==-1) return; var b = document.getElementsByTagName('body')[0]; b.insertBefore(e,b.firstChild); var x = function() { document.cookie = s+'; path=/'; e.parentNode.removeChild(e); }; e.addEventListener('click',x); document.addEventListener('scroll',x); })();