Question

1. calculate S = (1/1^2 + 1/2^2 + 1/3^2 + ... and so on), with 1%...

1. calculate S = (1/1^2 + 1/2^2 + 1/3^2 + ... and so on), with 1% accuracy. Make the accuracy to be a parameter that can be assigned. For example, acc=0.01. Use "sum1" code as a template. You will need an idea for the "accuracy part" since N is not given. My suggestion: when you add a next term to S (let's say 1/n^2), check if dS/S >= acc. If 'yes' then you continue, if 'not' then you are done and can quit the loop.

program should be in c++ coding.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#source code:

#include<iostream>

#include<cmath>

using namespace std;

int main(){

float total=0,i=0,check;

while(1){

check=1/(pow(++i,2));

if(check>=0.01){

total+=check;

}

else{

break;

}

}

cout<<"The total value :"<<total<<"\n";

return 0;

}

#if you  have any doubt comment below..

Add a comment
Know the answer?
Add Answer to:
1. calculate S = (1/1^2 + 1/2^2 + 1/3^2 + ... and so on), with 1%...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Coin 1 has bias p1, coin 2 has bias p2, coin 3 has bias p3. All...

    Coin 1 has bias p1, coin 2 has bias p2, coin 3 has bias p3. All coin flips are independent. We choose one of the three coins at random (each coin equally likely). Then we toss n times. Let's say K is A RANDOM VARIABLE the indicates the number of heads. Can we approximate K as normal? If yes what is mean and variance in this case? Let's say we toss coin 1 n1 times, coin 2 n2 times and...

  • In python 3, 1. Write a program that takes a number of credit hours and returns...

    In python 3, 1. Write a program that takes a number of credit hours and returns a classification as follows: 29 credits or less: freshman; 30-59 credits: sophomore; 60-89 credits: junior; 90+ credits: senior. 2. Use a loop to valid input such that users can only enter positive numbers. 3. Use a loop to allow the user to keep entering credit hours and receiving classifications until they quit. All code must be in a function. I suggest the following structure:...

  • Can you comment notes along with the code so I can follow along and understand what is being written?? Thanks in advance...

    Can you comment notes along with the code so I can follow along and understand what is being written?? Thanks in advance! Let's say we're in a directory and we want to rename every file ending in·c, to end in .C (i.e., capitalize the c'). Here's one way to do it: $ for i in *. c; b-basename "$1" .c'; mv "8b.c" do "8b.C". done Things get more complicated if you want more complex renaming. Say for example you just...

  • 2. Calculate the flux of the vector field F (2ry,-y2 + 3y, 1) through the surface with boundary S...

    2. Calculate the flux of the vector field F (2ry,-y2 + 3y, 1) through the surface with boundary Soriented with the outward unit normal in the figure below. Assume the volume of the solid E which lies inside the surface S and above the ry plane is 2π. Follow the following steps. [Warning: The problem is very similar to the one in PS11 but they are not the same. We can not apply the Divergence Theorem to S since it...

  • 1. Give the Python program that computes the square of a number. The number is passed...

    1. Give the Python program that computes the square of a number. The number is passed to the function as a parameter. The output is the square of this number. For example, the function can be used as shown below . . . . n = s q u a r e ( 7 ) . . . 2. Another very useful feature of Python is looping, which is more flexible than that available in BB. For example: while i...

  • PYTHON 3 - please show format Question 2. ) Use the Design Recipe to write a...

    PYTHON 3 - please show format Question 2. ) Use the Design Recipe to write a function yesOrNo which has no parameters. When called, it gets input from the user until the user types either 'yes' or 'no', at which point the function should return True if the user typed 'yes' and False if the user typed 'no'. Any other entries by the user are ignored and another value must be input. For example: Test Input Result print(yesOrNo()) hello blank...

  • Consider the following definite integral: In z dr- 2 ln 2-1 s 0.3862943611 1. Determine the smallest value for n so...

    Consider the following definite integral: In z dr- 2 ln 2-1 s 0.3862943611 1. Determine the smallest value for n so that T, is within 0.01 of In z dz. (JEri s A IE,K KIba 3 foss-In Ko.01 12n 1 (2-)S 12AM CO01 K=If"Gl=1 n2.98675 2 Sketch a dingm representing Ta. for the n you found above. The graph of y- In z is below -1 3. Compute the value of T, for the n you found above. (recall: T,-4f(zo)...

  • A machine that is programmed to package 2.95 pounds of cereal in each cereal box is...

    A machine that is programmed to package 2.95 pounds of cereal in each cereal box is being tested for its accuracy. In a sample of 33 cereal boxes, the mean and the standard deviation are calculated as 2.97 pounds and 0.06 pound, respectively. (You may find it useful to reference the appropriate table: z table or table) a. Select the null and the alternative hypotheses to determine if the machine is working improperly, that is, it is either underfilling or...

  • C++ (1) Prompt the user to enter a string of their choosing (Hint: you will need...

    C++ (1) Prompt the user to enter a string of their choosing (Hint: you will need to call the getline() function to read a string consisting of white spaces.) Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue!...

  • Rewrite the following for loop into a whileloop. 1 2 3 4 int s = 0;...

    Rewrite the following for loop into a whileloop. 1 2 3 4 int s = 0; for (int i = 1; i <= 10; i++) {    s = s + i; } Given variables int n and double pi, write a snippet of code that assigns to pi the approximation of π resulting from adding the first nterms in the Gregory-Leibniz series: Given variables int areaBound and int sum, write a snippet of code that assigns to sum the result...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT