Rabu, 18 April 2012

C++ Mencetak Deret Fibonancci

01.38



#include
#include

using namespace std;
class fibonacci{
friend istream& operator>>(istream&, fibonacci&);
friend ostream& operator<<(ostream&, fibonacci&);
public:
fibonacci();
void proses();
void jumlah();
private:
int x[100];
int a,hasil;
};


istream& operator>>(istream& in, fibonacci& masukan){
cout<<”Masukkan Banyak Suku :”;
in>>masukan.a;
}
ostream& operator<<(ostream& out, fibonacci& keluar){
out<<”Suku Fibonacci :”<<
out<<”Deret Fibonacci :”;
for(int i=0; i
out<<<”,”;
}
out<
out<<”Hasil Jumlah Deret Fibonacci :”<<
}
fibonacci::fibonacci(){
cout<<”\t\t<< PROGRAM MENCETAK DAN MENGHITUNG DERET FIBONACCI >>”<
}
void fibonacci::proses(){
if(a==1) hasil=1;
else if(a==2) hasil=1;
else
x[0]=1;
x[1]=1;
for(int i=2; i
x[i]=x[i-1]+x[i-2];
}
}
void fibonacci::jumlah(){
hasil=0;
for(int i=0; i
hasil=hasil+(x[i]);
}
}
int main(int argc, char *argv[])
{
fibonacci x;
cin>>x;
x.proses();
x.jumlah();
cout<
system(“PAUSE”);
return EXIT_SUCCESS;
}


Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

0 komentar:

Posting Komentar

 

© 2013 Raizexe Blog. All rights resevered. Designed by Templateism

Back To Top