Please write a C++ program that approximates the value of/4 using the formula /4 = 1 - 1/3 + 1/5 - 1/7 + 1/9 - .... Stop when the added or subtracted term is less than10-6 (1E -06). Need to use While Loop Please write a C++ program that approximates the value of/4 using the formula /4 = 1 - 1/3 + 1/5 - 1/7 + 1/9 - .... Stop when the added or subtracted term is less than10-6 (1E -06). Need to use While Loop
Explanation / Answer
#include #include using namespace std; int main() { int n = 0; int i = 1; double answer = 1; double approximate = 0; while ( abs( answer ) >= .000001 ) { answer = (pow( -1.0, n)) / i; approximate = approximate +answer; n++; i = i + 2; } cout