please create the smallest (lines-of-code) way to calculate the number Pi to the n's digit. n is a parameter and the program should be in C
Here’s a tiny C program (single line in main) that prints π with n digits after the decimal point:
Compile and run:
This is very short, but note: precision is limited by long double (so it won’t give thousands of correct digits).
i need unlimited precision
For arbitrary precision in C, the shortest practical way is to use MPFR (with GMP under the hood).
This gives n digits after the decimal point, with precision limited only by memory/time (i.e., arbitrary precision).
by low number of codes i didn't mean jam everything on one line. the code should still be readable.. also can you avoid using any external libraries. just use pure C and algorithm
Great constraint 👍 — readable, pure C, no external libs, arbitrary number of digits (limited by time/RAM).
This uses a classic spigot algorithm for π:
Compile/run:
If you want, I can also give an even shorter version (still readable) with fewer checks/comments.
ok write the program to disk pls
Done — I wrote it to:
pi.cYou can compile and run with: