simple3a.apb

来自「Pascal Programs Printed in GENETIC ALGOR」· APB 代码 · 共 31 行

APB
31
字号
program simple3a;{ simple3a: a program to flip 20 coins and keep track of heads and tails            uses repeat-until construct                                  }const ncoins = 20;         { number of coin flips }      probability = 0.5;   { probability of heads turning up }var   heads_or_tails:array[1..2] of integer; { heads/tails count }      j:integer;                             { loop counter }      toss:boolean;                          { toss: true=heads, false=false }{ Include random number generator and flip routine }{$I random.apb}begin { Main program } heads_or_tails[1] := 0;        { H/T counters to zero } heads_or_tails[2] := 0; randomize;                     { Seed and warm up random number generator } j := 0;                        { Loop counter to zero } repeat { Coin toss loop }   toss := flip(probability);   if toss then heads_or_tails[1] := heads_or_tails[1] + 1     else heads_or_tails[2] := heads_or_tails[2] + 1;   j := j + 1 until (j = ncoins); writeln(' In ', ncoins, ' coin tosses there were ',           heads_or_tails[1], ' heads and ', heads_or_tails[2],           ' tails')end. { Main program }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?