home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
CPROG
/
PI-5WAYS.ZIP
/
PI2.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-06-15
|
1KB
|
44 lines
/**************************************************************************/
/* Calculation of π by James Gregory (ca. 1671) approximation */
/* π = 4 { 1 - 1/3 + 1/5 - 1/7 + 1/9 ... +[(-1)**n]/[2*k+1] ... } */
/* */
/* */
/* Mendel Cooper */
/* 3138 Foster Ave. */
/* Baltimore, MD 21224 */
/* */
/* 06/91 */
/* Source code placed in the public domain */
/**************************************************************************/
/* may need #include <math.h> */
#define MAX 5000
main()
{
double intermediate_result = 0,numerator,Pi;
register int k;
for (k = 0; k <= MAX; k++)
{
if(k%2)
numerator = -1.0;
else numerator = 1.0;
intermediate_result += numerator / (2*(double)k +1);
Pi = 4.0 * intermediate_result;
printf("Term #%5d ------> π ≈ %f \n",k,Pi); }
}