ex49.pp 620 B

123456789101112131415161718192021222324
  1. Program Example49;
  2. { Program to demonstrate the Random and Randomize functions. }
  3. Var I,Count,guess : Longint;
  4. R : Real;
  5. begin
  6. Randomize; { This way we generate a new sequence every time
  7. the program is run}
  8. Count:=0;
  9. For i:=1 to 1000 do
  10. If Random>0.5 then inc(Count);
  11. Writeln ('Generated ',Count,' numbers > 0.5');
  12. Writeln ('out of 1000 generated numbers.');
  13. count:=0;
  14. For i:=1 to 5 do
  15. begin
  16. write ('Guess a number between 1 and 5 : ');
  17. readln(Guess);
  18. If Guess=Random(5)+1 then inc(count);
  19. end;
  20. Writeln ('You guessed ',Count,' out of 5 correct.');
  21. end.