Compile with
cc -o pi -O2 pi.c
The default precision of the calculation is 10,000 digits. Change this by means of the constants MAXSIZE and MAXDIGITS. I once calculated one million digits with it; this took 5 hours on an 800 MHz PC. This program is not particularly fast, but it is (hopefully) easy to understand.
When I first wrote this for MS-DOS on a 286 in 1989, I had to let it run overnight to get 10,000 digits. On my present computer (5500 BogoMips, and a lot cheaper than the one I had then) it takes less than one second. All hail Moore’s Law!
NOTE: On this site it says that calculating pi to one thousand digits took 40 hours on an Apple II in 1978. The improvement in hardware capability in a quarter-century is really astonishing (the algorithm scales as O(n²)). But software also has become better; now there are algorithms for calculating pi which are many orders of magnitude more efficient than the old Machin algorithm. For instance, hfloat on my machine calculates one million digits of pi in less than half a minute (the results, fortunately, agree with the Machin algorithm). But I can understand Machin, at least. The new stuff is way beyond my understanding!
NOTE: (25 October 2008) I tried compiling this program on a PowerPC machine today (actually, a ‘Bubba2’), and it did not work! That is, it compiled alright, but the calculation failed. The reason was an interesting phenomenon called ‘difference in endianness’. i386 PC's and several others are ‘little-endian’, while PowerPC's and several others are ‘big-endian’. I changed the code and believe it will now produce good results on both types of machine, provided you use gcc.