#include <conio.h> #include <iostream.h> class Operator{ friend ostream& operator<<(ostream&, Operator&); friend istream& operator>>(istream&, Operator&); 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, Operator& a) { for (int i=1;i<=a.n;i++) out<<fibonacci(i)<<""; return out; } istream& operator>>(istream& in, Operator& a){ cout<<"sampai suku ke- "; in>>a.n; return in; } main() { Operator run; cin>>run; cout<<run; getch(); }
Monday, April 16, 2012
Program Menhitung Suku Ke-n Dari Deret Fibonacci (Rekursif)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment