當前位置:編程學習大全網 - 編程軟體 - 求解bat和C語言還有VB計算圓周率的代碼。

求解bat和C語言還有VB計算圓周率的代碼。

算法[ma教教主]說的很明白了,直接貼代碼了。

C:

#include?

long?a?=?10000,?b,?c?=?2800,?d,?e,?f[2801],?g;

main()?

{?

for(;?b-c;?)?

f[b++]?=?a?/?5;

for(;?d?=?0,?g?=?c?*?2;?c?-=?14,?printf(%.4d,?e?+?d?/?a),?e?=?d?%?a)

for(b?=?c;?d?+=?f[b]?*?a,?f[b]?=?d%?--?g,?d?/?=?g--,?--?b;?d?*=?b);

}

VB:

Dim?sum?As?Double,?t?As?Double

Dim?N?As?Integer

N?=?6?'N是計算精度,越大越精確,但運算越慢?

sum?=?0:?t?=?1

Do

sum?=?sum?+?(-1)?^?(t?+?1)?/?(2?*?t?-?1)

t?=?t?+?1

Loop?Until?Abs((-1)?^?(t?+?1)?/?(2?*?t?-?1))?<?10?^?(-N)

Magbox?4?*?sum

BAT:

@echo?off?

SETLOCAL?ENABLEDELAYEDEXPANSION?

set?pi=400000000

set?t=0

set?p=3

set?times=0

set?det=-1

set?p1=-3

:loop

set?/a?

t=400000000/p1

set?/a?pi=pi+t

set?/a?p=p+2

set?/a?det=det*-1

set?/a?

p1=p*det

set?/a?times=times+1

if?%times%?geq?4000?goto?ex?::?可以寫成?if?%times%?geq?40000?goto?ex

goto?loop

:ex

set?/a?pi=pi%%100000000

echo?結果?3.%pi%

pause

  • 上一篇:UGNX新手建模實例教程圖例分享
  • 下一篇:單片機編程8個led燈,讓最低燈亮,循環左移s
  • copyright 2024編程學習大全網