CSCI 116
Project #6: Computing
Pi
Purpose:
Since everyone else
seems to do it when they get a computer, I suppose we have to as well. For this project, we are going to compute the
value for π (pi). We aren’t going
to get as carried away as the supercomputer guys do and compute millions of
digits. We are going to be a bit more
modest and just compute the first 15 or so digits using doubles.
Program Objective: To compute and print the first 15 digits
of π.
Instructions: Write a program to compute and print
π. To compute the value of π,
we need a formula for it. Let’s use the
standard formula1,
This is all
well and good, but in order to compute π, we need to compute arctan
now. We could try to use a standard
function from cmath, but let’s write our own function
to compute arctan. Mathematicians tell
us an easy formula to use is
This shouldn’t
be too bad since it looks like the computation for
Here is a
sample output from the program:
Pi = 3.14159265358979
Press any key to continue
NOTE: You are to implement functions
for arctan, pi, and exponentiation. You
are to use the formulas above in your computation. Going on line and finding C++ code that
computes π and turning it in as your own is considered plagiarism, and will result in a zero (0) for the project as well as
other consequences!
Have fun!
1Note: the formulas
sometimes don’t show up in Chrome. If
they don’t, try using a different browser, such as Internet Explorer. If none of them work, here is the page as a pdf)