Home > Back-end >  With one-third of PI/4=1-1/5-1/7... Formula for PI.
With one-third of PI/4=1-1/5-1/7... Formula for PI.

Time:10-11

#include
The main ()
{
Int I, j, n.
Int sum=0;
For (I=1, j=1;; I=I + 2, + + j)
{if (j % 2==0)
I=1/I;
The else
I=1/I;
Sum=sum + I; }
N=sum * 4;
Printf (" n=% d \ n ", n);
}
Why isn't the result? For help

CodePudding user response:

I for int, you 1/I what is the result? In addition to the first, the rest is probably all is zero?

CodePudding user response:

Put all the data type to float or double then it is ok to run,,

CodePudding user response:

The data type should pay attention to

CodePudding user response:

I, n, the sum of the need to be modified into a floating-point data types, and then I=1/I should be represented in a floating point lose such as float x=- I/1
Hope to help you

CodePudding user response:

To high precision need double or long double data type,
  • Related