0

I am trying to use an ALU and Leibniz Series to approximate pi using only integer operations ie multiplication and shifting. Does anyone know how I could program this in C?

  • Depending on what the purpose of this exercise is, use of a [*spigot algorithm*](https://en.wikipedia.org/wiki/Spigot_algorithm) may be a good choice. As far as I know, the algorithms are not based on the Leibniz formula for π, however. – njuffa Mar 07 '20 at 20:57

1 Answers1

0
sum = 0;

for (int i = 1; i <= 10; i++) {
  sum = sum + (-1) * (1 / (2.0 * i + 1));
}

Printf("Pi=%f",4 * (sum + 1));
Norbert
  • 2,741
  • 8
  • 56
  • 111