| Algoritma jumlah deret | 
| Deklarasi n, jumlah, x : integer | 
| Deskripsi jumlah = 0 i = 0 repeat jumlah = jumlah+(1/i) i = i+1 selisih = (1/i)-(1/(i-1)) until abs (selisih)<0.001 write(jumlah, i) | 
Listing
| #include   <iostream> | 
| #include   <conio.h> | 
| #include   <cstdlib> | 
| #include   <math.h> | 
| using   namespace std; | 
| class   Deret{ | 
|       friend ostream&   operator<<(ostream&, Deret&); | 
| public: | 
|        float hitung_Deret(); | 
| private: | 
|         int n; | 
|         float hasil; | 
|         }; | 
| float   Deret::hitung_Deret(){ | 
|       float selisih, jumlah = 0.0; | 
|       int i = 1; | 
|       do{ | 
|            jumlah += 1.0/i; | 
|            i++; | 
|            selisih = 1.0/(i-1)-1.0/i;} | 
|            while(selisih>=0.001); | 
|            cout<<" PERULANGAN   DILAKUKAN SEBANYAK : "<<i<<endl; | 
|            return jumlah; | 
|            } | 
|       ostream&   operator<<(ostream& out, Deret& A){ | 
|                out<<" JUMLAH DERET   = "<<A.hitung_Deret(); | 
|                return out; | 
|                } | 
| int   main(){ | 
|     Deret x; | 
|     cout<<x; | 
|     getch(); | 
|     return 0; | 
| } | 

 
Tidak ada komentar:
Posting Komentar