Re: C Program confused me
Check out sci.math & the sci.math FAQ (lost the url-sorry) - the faq has
extensive descriptions of several different algorithms for calculating pi.
At 06:47 PM 3/12/99 +0800, Bal K. Paudyal wrote:
>Hello Friends,
>
>I encountered following program in one of the Linux Howtos. This calculates
>the value of pai. But how does it do this? I am not asking the programming
>details, but on what theory the formula is based on. Can anybody help? Is
>there any better place to look for help?
>
>
>
>---------------------------------------
>#include <stdlib.h>;
> #include <stdio.h>;
>
> main(int argc, char **argv)
> {
> register double width, sum;
> register int intervals, i;
>
> /* get the number of intervals */
> intervals = atoi(argv[1]);
> width = 1.0 / intervals;
>
> /* do the computation */
> sum = 0;
> for (i=0; i<intervals; ++i) {
> register double x = (i + 0.5) * width;
> sum += 4.0 / (1.0 + x * x);
> }
> sum *= width;
>
> printf("Estimation of pi is %f\n", sum);
>
> return(0);
> }
>--------------------------------
>
>
>--
>Unsubscribe? mail -s unsubscribe debian-user-request@lists.debian.org <
/dev/null
>
>
>
Reply to: