In: Computer Science
Use a while(true) loop to ask the user the following 2 values
“Enter a value x “ “Enter a nonnegative integer n (enter negative
integer to quit): “
If the user enters a negative int for n, the while loop is broken
via the brake statement. Otherwise,
in the remaining part of the while loop, use a for loop to compute
the partial sum for the Riemann
zeta series for the geometric series, namely 1 + 2ˆ-x + 3ˆ-x + . .
. + nˆ-x.
Use the iomanip library in order to print the sum with 50 decimal
digits of precision.
Use the cmath library in order to access the pow function. For
example pow(3,-x) returns the value
of 3ˆ-x.
Sample output:
Enter a value x = 5
Enter a non-negative integer (enter negative integer to quit):
4
1 + 2^-5 + 3^-5 + 4^-5 =
1.0363417888374486519609263268648646771907806396484
Enter a value x = -5
Enter a non-negative integer (enter negative integer to quit):
4
1 + 2^5 + 3^5 + 4^5 = 1300
Enter a value x = 6
Enter a non-negative integer (enter negative integer to quit):
-2
C++.will like if correct,thank you.
Program :-
#include <iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main() {
int x, n, i;
float result = 0;
while(true)
{
cout << "Enter a value x = ";
cin >> x;
cout << "Enter a non-negative integer (enter negative integer
to quit) : ";
cin >> n;
if(n<0)
break;
for(i=1; i<=n; i++)
{
result = result + pow(i, -x);
if(i==1)
cout << i ;
else
{
cout << " + " << i << "^" << -x;
}
}
cout << " = " << setprecision(50) <<
result;
cout << "\n";
result = 0;
}
cout << "-------------------EXIT-------------------";
cout << "\n";
return 0;
}