⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simple3b.apb

📁 Pascal Programs Printed in GENETIC ALGORITHMS IN SEARCH, OPTIMIZATION, AND MACHINE LEARNING by Da
💻 APB
字号:
program simple3b;{ simple3b: a program to flip 20 coins and keep track of heads and tails            uses while-do 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 := 1;                        { Loop counter to zero } while (j<=ncoins) do begin  { 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  end;    { Coin toss loop } 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -