I need a C code that will produce the solution of a code bel
I need a C++ code that will produce the solution of a code below.
Note that this is a C++ code also that each space in the picture is a different trial run of the solution.
Prompt and read the value of n from the user. This value must be 1. Use a while loop to repeatedly prompt and re-read this value from the user if a value entered is invalid. Use for loop(s) to compute the alternating series (see above). Print the resulting sum. If your sums approach the value of ln (2) on your calculator then your program is probably correct.
Enter n: 6 The alternating series converges to 0.616667 Enter n: 95 The alternating series converges to 0.698383 Enter n -5 value n must be 1 or greater. Try again:Solution
Program:
#include <iostream>
#include \"math.h\"
using namespace std;
int main() {
while(1)
{
int n=0;
cout << \"Enter n: \";
cin>>n;
if(n<1)
{
cout << \"Value of n must be 1 or greater.Try Again \" ;
cin>>n;
}
double sum = 0;
for(int i=1; i<n; i++) {
sum = sum + pow(-1.0, i+1.0)/i;
}
cout << \"Alternating Series Converges To: \" << sum << endl;
}
return 0;
}
