Google Answers Logo
View Question
 
Q: Basic Program to find decimal places for PI ( Answered 5 out of 5 stars,   2 Comments )
Question  
Subject: Basic Program to find decimal places for PI
Category: Computers > Programming
Asked by: kaiserwilhelm-ga
List Price: $6.00
Posted: 25 Jun 2002 16:01 PDT
Expires: 25 Jul 2002 16:01 PDT
Question ID: 33189
I have an old Commodore 64. I used to be able to program on the old
thing pretty good. Would like a C-64 or generic basic program that
would find the decimal places of PI.
I would like to be able to show my daughter how to program a computer
and get it to do something simple like this. I know how to get it to
look at the decimal place and see if it is repeating....I do not know
the mathmatical ratio I put in to get it started.
Answer  
Subject: Re: Basic Program to find decimal places for PI
Answered By: skermit-ga on 25 Jun 2002 16:26 PDT
Rated:5 out of 5 stars
 
Hello,

Nice question. Calculating PI mathematically using recursive formulas
is your best bet. Short programs can be achieved in about 10 lines or
so which get more and more closer to actual PI the longer and longer
you run them. First I would like to direct your attention to the
howstuffworks.com page (listed below). It has a lot of information
about the basics of calculating PI and the history behind it.

ticalc.org celebrated PI day (March 14th, 3/14 ... get it? heh) two
years ago by writing a short article on how to write a small program
for your calculator to output PI. (linked below) Here is their short
program in Basic (TI Basic, but the structure should be the same for
C64 Basic, just maybe the commands are a little different):

ticalc.org program for PI:

":0 --> N0 --> D
:While 1
:rand*2-1 --> X
:rand*2-1 --> Y
:If sqrt(x^2+y^2)=< 1
:N+1 --> N
:End
:D+1 --> D
:Disp (N/D*4)
:End"


I also found a much longer basic program for DOS qbasic which would
probably be easier to translate into C64 Basic. (linked below)

And ticalc.org again has 3 more examples on calculating PI in TI-basic
with code examples in ZIP format. (linked below)


Additional Links:

How Stuff Works - PI:
http://www.howstuffworks.com/pi.htm

QBASIC PI Program:
http://www.basicguru.com/files/abc/abc9705/pi.bas

3 more implementations of PI:
http://www.ticalc.org/pub/89/basic/math/calcpi.zip


Search Strategy:

basic program for calculating pi:
://www.google.com/search?q=basic+program+for+calculating+pi

"+in basic" "calculate pi" on google:
://www.google.com/search?q=%22%2Bin+basic%22+%22calculate+pi%22


With all of these examples, you should have no problem teaching your
daughter about this magical number!

Thank you for the opportunity to answer your question, if you require
more information, please clarify the question, or if you find this
answer satisfactory, please feel free to rate it. Thank you!
   
skermit-ga

Clarification of Answer by skermit-ga on 25 Jun 2002 16:31 PDT
Oops, I forgot the PI day article on ticalc.org... enjoy!


Additional Links:

http://www.ticalc.org/archives/news/articles/2/28/28666.html


skermit-ga
kaiserwilhelm-ga rated this answer:5 out of 5 stars
Exactly what I was looking for. Thank you for the "extra mile'!

Comments  
Subject: Re: Basic Program to find decimal places for PI
From: googlebrain-ga on 25 Jun 2002 18:34 PDT
 
Oh man... This is such a blast from the past. Somewhere... Somewhere,
I have a disk with a program that caused a 1541 Disk Drive to
calculate Pi, and write the data to an inserted disk. I was very bored
that week. If I can find it (Even if I still have the disk, it'll be
seriously old) I'll post the source here. It wasn't very long, but it
was all ML (Obviously, since the drive didn't support any high level
languages :)

googlebrain-ga
Subject: Re: Basic Program to find decimal places for PI
From: wengland-ga on 26 Jun 2002 12:07 PDT
 
How To:

http://www.cecm.sfu.ca/organics/papers/borwein/paper/html/paper.html

Perl code:
http://groups.google.com/groups?dq=&hl=en&lr=&ie=UTF-8&oe=UTF8&selm=8E86873BFquuxi%4010.1.2.158

More Perl Code:
http://groups.google.com/groups?dq=&hl=en&lr=&ie=UTF-8&oe=UTF8&selm=80qebl%2415f93%241%40fu-berlin.de

And some C code:
http://groups.google.com/groups?selm=1992Oct16.004343.9068%40cs.aukuni.ac.nz&oe=UTF8&output=gplain

Enjoy!

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy