0
Fibonacci Series using Constructor
How to make an OOPs program, using Constructor, to print a Fibonacci series upto a number 'n'?
2 Respostas
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);
};
0
that would be one way