eucleia: (Studious)
eucleia ([personal profile] eucleia) wrote2008-12-21 02:28 am

Printing Pi up to 10,000 digits using C-programming

This program, written in C, allows to to print π to however many decimal places you want and also tells you at the end the computing time.

The original source code was gleaned from the following link (piclassic.c), and was written by Pascal Sebah.
http://numbers.computation.free.fr/Constants/constants.html


This algorithm utilizes the extremely efficient and rapidly converging Machin-like method and formulae to find the value of Pi(π) accurate to up to 10000 decimal places.

When running the program in newer versions of C, however, I found that despite the program working correctly, it printed pi to 10000 decimal places arbitrarily and also seemed to show some runtime errors. I have fixed these, rearranged the program from a single source file to two plus a header to make it neater, changed the function layouts (did old versions of C call them differently?), and also altered it to allow the user to choose the number of digits they would like pi to be printed to.
Original base code however, goes to Pascal Sebah.

If you are using this for an assignment in school/university/etc. then credit both me and Pascal Sebah and for goodness sake change some of the coding or the layout of it so that it's at least some of your own work. At the very least, alter the names of the project, main, functions and header source files. And oh, if it doesn't work, it's because you didn't alter the name of the header file, nor the coding to reflect that.

Remember: Crediting is your friend. I'm not trying to be nasty here, it really is for your own good. Since the coding is right here, all a lecturer has to do is copy-paste a tiny section into a search engine and they'll find it. Or they could just type in "coding for pi" as well. Believe me, lecturers can have some badass Google-fu skillz.

The main program.
- Minor runtime error in which original main() was declared as 'void' instead of 'int'. While it still works, C doesn't like that.
- Program can now ask for how many decimal places you actually want it to print.




The functions file.
- Changed the layout and way in which the functions are called/defined. Extra curly brackets basically.



The header file.
- Added function protocols so that the program would work in seperate parts.
- The header file does little, except to make the main and functions files less clunky, and also to eliminate repeating of code.




And this following flag counter is simply for my own amusement, to see how many of you guys are actually reading or making use of this stuff. (^_^) Hope it helps.
free counters

[identity profile] smilingcrescent.livejournal.com 2008-12-21 04:32 am (UTC)(link)
...you do realize that this made me go, "...what...?"

XD

cool. no idea what it's doing, but...cool.

[identity profile] midgar-skyline.livejournal.com 2008-12-21 03:35 pm (UTC)(link)
XDDD Huwhy sankyuu. :3

Glad you think it's cool. Basically it's a program that allows you to show the digits of pi accurately to 10000 decimal places by using Machin-like formulae instead of the usual circumference divided by diameter thing, because the program wouldn't understand what a circle was. XD;

[identity profile] liyosa.livejournal.com 2008-12-22 01:41 am (UTC)(link)
I hate convergence formulas....

But that looks freakin' fascinating.

Nice job!

[identity profile] midgar-skyline.livejournal.com 2008-12-22 02:25 pm (UTC)(link)
I hate them too. DD8 This is a simple-ish one though - it's a Maclaurin Expansion which is better, because the top reduced to 1. I hate regular Fourier series though. >(((

Thank you very much! XD