Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Monte-Carlo-methods/Seed7/monte-carlo-methods.seed7
Normal file
26
Task/Monte-Carlo-methods/Seed7/monte-carlo-methods.seed7
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
$ include "seed7_05.s7i";
|
||||
include "float.s7i";
|
||||
|
||||
const func float: pi (in integer: throws) is func
|
||||
result
|
||||
var float: pi is 0.0;
|
||||
local
|
||||
var integer: throw is 0;
|
||||
var integer: inside is 0;
|
||||
begin
|
||||
for throw range 1 to throws do
|
||||
if rand(0.0, 1.0) ** 2 + rand(0.0, 1.0) ** 2 <= 1.0 then
|
||||
incr(inside);
|
||||
end if;
|
||||
end for;
|
||||
pi := flt(4 * inside) / flt(throws);
|
||||
end func;
|
||||
|
||||
const proc: main is func
|
||||
begin
|
||||
writeln(" 10000: " <& pi( 10000) digits 5);
|
||||
writeln(" 100000: " <& pi( 100000) digits 5);
|
||||
writeln(" 1000000: " <& pi( 1000000) digits 5);
|
||||
writeln(" 10000000: " <& pi( 10000000) digits 5);
|
||||
writeln("100000000: " <& pi(100000000) digits 5);
|
||||
end func;
|
||||
Loading…
Add table
Add a link
Reference in a new issue