8. Write a Program to generate Fibonacci Series by using Constructor to initialize the Data Members.
// FIBONACCI SERIES using CONSTRUCTOR
#include<iostream>
#include<iomanip>
class fibonacci
{
int n1,n2;
public:
fibonacci()
{
n1 = 0; n2 = 1;
}
void series(int);
};
void fibonacci::series(int n)
{
int i,next;
cout << setw(4) << n1 << setw(4) << n2;
for(i=1; i <= n-2; i++)
{
next = n1 + n2;
cout << setw(4) << next;
n1 = n2; n2 = next;
}
}
int main()
{
fibonacci fib;
int n;
cout << "FIBONACCI SERIES\n";
cout << "How many numbers? ";
cin >> n;
fib.series(n);
}
This comment has been removed by the author.
ReplyDeletewhat is the use of setw(4)...?
ReplyDeleteYes agree with you ..
DeleteThank you so much for this example.
ReplyDeleteIf you need any software solutions,custom software development company
Want Algorithm for this
ReplyDelete