folwchart
Program :
#include <cstdlib>
#include <iostream>
#include <math.h>
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<<(operator& out, Deret& A) {
out << "Jumlah Deret = "A.hitung_Deret();
return out;
int main(){
Deret X;
cout<< X;
system("pause");
return 0;
}
Related Posts