by Louis-Charles Trudeau (1 Submission)
Category: Math/Dates
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Mon 15th November 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Calculate pi depending on how much time you do the For ( if you put n = 0 to 1000, it'll be less acurate than n = 0 to 1000000 )
API Declarations
Dim nb As Long
Dim n As Long
Dim x, res As Double
'---------------IF YOU WANNA UNDERSTAND READ THIS ---------------
'Formula of Pi : 4/1 - 4/3 + 4/5 - 4/7 + 4/9... see the patern? it's simple
'n = 0 to infinite : Pi = Pi + 4 x (1 / 2n + 1) x (-1)^n
'(4 x ( 1 / (2n + 1))) = 4/1 or 4/3 or 4/5 or...
'(-1)^n is to change the sign of the number :
'(-1)^1 = -1 , (-1)^2 = 1, (-1)^3 = -1 ... SIMPLE
'----------------------------------------------------------------
For n = 0 To nb
x = (4 * ((1 / (2 * n + 1))) * (-1) ^ n)
res = res + x
Next n
MsgBox Str(res)
End Sub
Private Sub Form_Load()
nb = Val(InputBox("Enter a number (1000000 : 7 accurate decimals)"))
pi_formula
End Sub
No comments have been posted about Calculate pi depending on how much time you do the For ( if you put n = 0 to 1000, it'll be less ac. Why not be the first to post a comment about Calculate pi depending on how much time you do the For ( if you put n = 0 to 1000, it'll be less ac.