program series with C + +

determine the value of:

1 +1 / 2 +1 / 3 + ... .... +1 / N

until the difference between the two levels of no more than 0.001. determine the value of n the last.

The first we do is how we create an algorithm that first, then try to implement in the form of the program:

declaration:
n, number, x: interger
Average: real
Description:
number <0 =
i <1 =
repeat
number <= number + (1 / i)
i <= i +1
Until abs (difference) <0.001
write (sum, i)


after the algorithm is finished we tried to pour in the form of programming language, and below is one form of language they use programs that use C + +

Let us carry out, but do not forget to include it's still not right and still no closing parenthesis is closed.

/ * By.parwito UAD coy
al pro Iki task * /

# Include> cstdlib
# Include # Include
using namespace std;
class array {
public:
hitung_deret float ();
private:
int n;
Float result;
};

float array:: Iki (){// kontructor hitung_deret
Difference float, Assets = 0.0;
int i = i;
do {
Asset + = 1.0 / i;
i + +;
Difference = 10 / (i-1) -1.0 / i;
} While (> Difference = 0.001);
court <<"loop do as much:" << Asset return;

}

ostream & operator <<(ostream & out, runs & A) {
out <<"rows Asset =" < return out;
}

main () {
array X;
court < system ("PAUSE");
return EXIT_SUCCESS;
}


0 comments:

Twitter Delicious Facebook Digg Favorites More