Answer to Question #188943 in C++ for zain ul abdeen

Question #188943

Q1.make a class of fabnacci series. This series is 1 1 2 3 5 8 13 21 and so on.


1
Expert's answer
2021-05-06T17:52:17-0400
#include <iostream>
using namespace std;
class Fibonacci{
    int* n, x;
    public:
    Fibonacci(int y): x(y){
        n = new int[x];
        for(int i = 0; i < x; i++){
            if(i == 0) n[i] = 0;
            else if(i == 1) n[i] = 1;
            else n[i] = n[i - 1] + n[i - 2];
        }
    }
    void show(){
        for(int i = 0; i < x; i++) cout<<n[i]<<" ";
    }
};
int main(){
    cout<<"Input number of fibonacci numbers to generate: ";
    int n; cin>>n;
    Fibonacci fib(n);
    fib.show();
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS