用BASIC计算PI
This post is written in Chinese. Please consider using Google Translate
昨天翻硬盘,累死我了400G的东西都看了一遍,结果发现了很早以前我写的程序。上小学时写的算PI的程序。
INPUT n
x = n * 2 - 1
a = 1 - 1 / 3
w = (x - 5) / 2 + 1
v = 100 / w
FOR y = 5 TO x STEP 2
IF (y - 1) / 4 = INT((y - 1) / 4) THEN
a = a + 1 / y
ELSE
a = a - 1 / y
END IF
u = u + v
PRINT u; "%"
NEXT y
a = a * 4
PRINT a