Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Quick Way to Calculate Pi
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
GlobeTrotter




PostPosted: Mon Apr 11, 2005 7:06 pm   Post subject: Quick Way to Calculate Pi

code:
var tempval : real := 0
var pi : real

for i : 1 .. 46340
    tempval += 1 / (i * i)
end for

pi := sqrt (6 * tempval)
put pi
put Math.PI


This works off the fact that pi^2/6 = 1 + 1/4 + 1/9 + 1/16 ...

edit: by the way, the reason I chose 46340 is because it is the largest number turing will let me use. In practice it should be infinite in order to truly calculate pi.
Sponsor
Sponsor
Sponsor
sponsor
windowsall




PostPosted: Mon Apr 11, 2005 8:54 pm   Post subject: (No subject)

isnt putting
const pi:real :=3.14....


a hek of a lot quicker then all that i mean yeah i see where your coming from i mean programming ids math and functions but isnt it also size of code and the const aboev with proper syntax would be the less buggiest as well would it not??? im still new at this and learning but jsut curious
GlobeTrotter




PostPosted: Mon Apr 11, 2005 8:58 pm   Post subject: (No subject)

Obviously loading turing's predefined Math.PI constant is quicker. I'm just showing a way to calculate pi.
Delos




PostPosted: Mon Apr 11, 2005 8:58 pm   Post subject: (No subject)

I really, really, really hope for your sake that you don't think that pi = 3.14.

The significance of this programme is not efficiency or reduced lines...it's simply very interesting maths that plays with your head when you try to figure it out. These types of relationships between irrational numbers and rational ones is something that math people love to play with.
And believe me, CompSci is maths. And lots of it.

BTW: GlobeTrotter, solve this: x^2 - x - 1 = 0...
MihaiG




PostPosted: Thu Apr 14, 2005 7:35 pm   Post subject: (No subject)

x = phi aka. the golden ratio = 1.61803399 muwuhhaah it was in teh Da Vinci Code....ur body= phi(measure from hip to toe and divde that by from knee to toe) you het a number roughly around phi muwuhahahahahaha **i know it was for globe but i had too Rolling Eyes


**edit** i wuv my sig
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: