Hello, there is a Bellara formula that should return the nth digit of pi in binary representation:

Formula

and there is my c # code:

while (true) { Console.WriteLine("Введите нужный разряд "); double n = Convert.ToInt32(Console.ReadLine()); double result = 0; double index = 0; do { result += (Math.Pow(-1, index) / Math.Pow(2, 10 * index)) * (-(Math.Pow(2, 5) / (4 * index + 1)) - 1 / (4 * index + 3) + (Math.Pow(2, 8) / (10 * index + 1)) - (Math.Pow(2, 6) / (10 * index + 3)) - (Math.Pow(2, 2) / (10 * index + 5)) - (Math.Pow(2, 2) / (10 * index + 7)) + 1 / (10 * index + 9) ); ++index; } while (index < n); Console.WriteLine((1.0 / Math.Pow(2, 6)) * result); } 

returning this:

enter image description here

Please tell me the error

  • Let's do this. And you framed handles, what should happen? What do you think is a mistake? I suppose that the algorithm returns a number that is exactly correct before the n-th character, and then no longer a fact. - Trymount
  • @Trymount - by (n-th digit of pi in binary representation), I understand for example the hundredth number in this sequence, in binary code - performance
  • In order to get a binary code in the response, you probably need to consider it in a binary system - Trymount
  • @Trymount - sorry, maybe I seriously did not understand. And I get the answer accurate to the n-th character. Then I need my data type in order to display on 100 characters? - performance
  • one
    the accuracy of the obtained value of Pi depends on n (the number of terms) and nothing more, binary digits have nothing to do with it. Based on it, you can calculate the required digit of Pi, but the formula itself is designed to calculate Pi itself, by the way, for n = 5, it gives the result equal to the constant Math.PI , up to the last sign of the constant, and not Pi itself, of course. About the method of calculating the necessary bits better read the author bellard.org/pi/pi_n2/pi_n2.html - rdorn

0