#include <iostream>
#include <conio.h>
using namespace std;
class Deret{
friend ostream& operator<<(ostream&, Deret&);
friend istream& operator>>(istream&, Deret&);
public :
long fibonacci(int);
private :
int n;
};
int fibonacci(int n){
if((n == 1)|| (n == 2)) return (1);
else return(fibonacci(n - 1) + fibonacci(n - 2));
}
ostream& operator<<(ostream& out, Deret& a){
for(int i = 1; i < a.n; i++)
out<<fibonacci(i)<<" ";
return out;
}
istream& operator>>(istream& in, Deret& a){
cout<<"Sampai suku ke : ";
in>>a.n;
return in;
}
int main(int argc, char *argv[])
{
Deret run;
cin>>run;
cout<<run;
system("PAUSE");
return EXIT_SUCCESS;
}
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment