Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int main (void)
- {
- /*
- Write a program that prompts the user to enter a number then compute the natural logarithm of 2,
- by adding up to n terms in the series where n is the number that the user entered.
- 1 - 1/2 + 1/3 - 1/4 + 1/5 -... 1/n
- */
- double sum = 0;
- int n = 1000;
- for (int i=1; i <= n; i=i+2)
- {
- sum += 1.0/i - 1.0/(i+1);
- }
- std::cout << sum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement