0

Fibonacci Series using Constructor

How to make an OOPs program, using Constructor, to print a Fibonacci series upto a number 'n'?

9th Nov 2018, 3:31 PM
Koustub Poddar
Koustub Poddar - avatar
2 Réponses
0
#include <iostream> using namespace std; class Fib{ public: Fib(int n){ int num1 = 1; int num2 = 1; int num3 = 1; for(int i=0;i<n;i++){ num1 = num2; num2 = num3; num3 = num1 + num2; cout<<i; cout<<". "; cout<<num1; cout<<"\n"; } } }; int main(){ int a; cin>>a; Fib fib(a); };
11th Nov 2018, 6:38 PM
Anton Böhler
Anton Böhler - avatar
0
that would be one way
11th Nov 2018, 6:42 PM
Anton Böhler
Anton Böhler - avatar