-7

I'm have to write a C program, what it does is takes a integer as input. And gives output to the input(th) number of PI after decimal. Like if input is 100, output will be 9(100th digit of pi, after decimal is 9). What will be the best algorithm for that?

p.s I don't want to save the value of pi into the string, and do it.

  • 2
    Please show your research/debugging effort so far. Please read [Ask] page first. – Sourav Ghosh Apr 28 '17 at 04:56
  • efficient for what? memory? time?... [Mysticial](http://stackoverflow.com/users/922184/mysticial) is the current world record holder for most digits computed and have a few programs to calculate it – phuclv Apr 28 '17 at 05:09

1 Answers1

4

Your question is more a math question than a C programming one (so perhaps off-topic). Read first the wikipage on Pi and Approximations of π

If you need to compute only a few hundred (or even hundred thousands) digits, you just need to use some algorithm and code it using some bignum library (e.g. GMPlib, which has mpfr_const_pî ass commented by chtz).

Things become interesting for many billions of digits. I'm not expert on Pi, but look into Fabrice Bellard work on it (read the technical notes mentioning Chudnovsky's algorithm).

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547