DEMO2-87.PAS 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. {$C-}
  2. program test;
  3. {
  4. TURBO-87 DEMONSTRATION PROGRAM Version 1.00A
  5. This program demonstrates the speed and precision advantages
  6. of the TURBO-87 compiler.
  7. INSTRUCTIONS
  8. 1. Compile and run this program using the TURBO.COM compiler.
  9. 2. Compile and run this program using the TURBO-87.COM compiler
  10. and compare the results with (1) above.
  11. }
  12. var
  13. Terms : integer;
  14. Answer: char;
  15. procedure GetTerms(var Count : integer);
  16. begin
  17. ClrScr;
  18. Writeln('This program demonstrates the speed and precision advantages');
  19. Writeln('of the TURBO-87 compiler.');
  20. Writeln;
  21. Write('Please tell me how many terms you want to add: ');
  22. HighVideo;
  23. readln(Count);
  24. Writeln;
  25. end; (* GetCount *)
  26. procedure DisplayResults(Count : integer);
  27. var
  28. Number, Sum : real;
  29. Index : integer;
  30. function InvSquare(arg: real): real;
  31. begin
  32. InvSquare := 1 / Sqr(arg)
  33. end; (* InvSquare *)
  34. begin
  35. Write('Calculating: 1/1 + 1/4 +... + 1/',Count,'*',Count,' = ');
  36. Sum := 0;
  37. for Index := 1 to Count do
  38. begin
  39. Number := Index;
  40. Sum := Sum + InvSquare(Number)
  41. end;
  42. Writeln(Sum:1:20);
  43. Writeln;
  44. LowVideo;
  45. end; (* DisplayResults *)
  46. begin
  47. LowVideo;
  48. repeat
  49. GetTerms(Terms);
  50. DisplayResults(Terms);
  51. Write('Type <ESC> to quit, any other key to continue...');
  52. Read(KBD, Answer);
  53. until Answer in [#27, ^C];
  54. end.
  55.