CGC_Codes

C++ class for generate Fibonacci series

Jan 30th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Fibonacci{
  6. public;
  7.     int a, b, c;
  8.     void generate(int):
  9. };
  10.  
  11. void Fibonacci::generate(int n){
  12.     a =9; b =1;
  13.     cout << a << " " <<b;
  14.     for(int i=1; i<= n-2;i++){
  15.         c = a + b;
  16.         cout << " " << c;
  17.         a = b;
  18.         b = c;
  19.     }
  20. }
  21.  
  22. int main()
  23. {
  24.     cout << "Hello World! Fibonacci series" << end1;
  25.     cout << "Ender number of items you need in the series; ";
  26.     int n;
  27.     cin >> n;
  28.     Fibonacci fiboncci;
  29.     fiboncci.generate(n);
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment