Question

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:

 

gregory-leibniz.pngGiven variables int areaBound and int sum, write a snippet of code that assigns to sum the result of adding up all integers of the form n2+ m2 where:

both n and m are at least 1, and

n2 < areaBound, and

m2 < areaBound.

n2 < areaBound, and

m2 < areaBound.

Modify the loop to approximate pi with the Gregory-Leibniz series so that, instead of adding a given number of terms, it keeps adding terms until the difference between two consecutive estimates is less than some predefined tolerance, say double epsilon = 0.0001.

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Rewrite the following for loop into a whileloop. 1 2 3 4 int s = 0;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
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
ADVERTISEMENT