List of all available Websheets
Viewing cpp/control/liebnizapprox by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | This program should use a loop to compute the result of the first 10 terms of Leibniz's approximation of $\pi/4$. See the comment in the code for the exact terms. |
Public permissions | |
Remarks Comments, history, license, etc. | Originally by Mark Redekopp (redekopp@usc.edu) and Dave Pritchard (daveagp@gmail.com) |
Engine | |
Template / Reference solution |
using namespace std; int main() { double approx; // write code that includes a for loop to compute the first 10 // terms of Liebniz's approximation to PI/4 which is: // (1/1) - (1/3) + (1/5) - (1/7) + ... - (1/19) \[ approx = 0.0; for(int i=0; i < 10; i++){ approx += pow(-1,i)/(2*i+1); } ]\ cout << "The approximate value is "; cout << setprecision(3) << approx << endl; return 0; } |
C++ test suite json list of stdin/args tests e.g. [{"stdin":"hi", "args":["4", "5"]}, {"stdin":"noargs"}] to just run once with no input use [{}] | [ {} ] |
Solution visibility |
Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.