qp.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
MATH.PAS
  Example Contents Index                                    Back
 
PROGRAM math;
 
{ MATH.PAS illustrates math functions, including:
 
      Abs     Int    Odd          Round    Sqrt
      Exp     Ln     Random       Sqr      Trunc
      Frac    Pi     Randomize
}
 
CONST
    program_name = 'MATH ';
    program_desc = 'demonstrates many math routines.';
 
VAR
    x,y : Real;
    i   : Integer;
 
BEGIN
 
    Writeln( program_name, program_desc );
    Writeln;
 
    Write( 'Enter a real number: ' );
    Readln( x );
    Writeln;
    Writeln( 'Function   Result for ', x );
    Writeln( '--------   -------------------------' );
    Writeln( 'Frac       ', Frac( x ):12:9 );
    Writeln( 'Int        ', Int( x ):3:1 );
    Writeln( 'Round      ', Round( x ) );
    Writeln( 'Trunc      ', Trunc( x ) );
    Writeln( 'Exp        ', Exp( x ) );
    IF (x > 0.0) THEN
        Writeln( 'Ln         ', Ln( x ) );
    IF (x >= 0.0) THEN
        Writeln( 'Sqrt      ', Sqrt( x ) );
    Writeln( 'Sqr       ', Sqr( x ) );
    Writeln( 'Abs       ', Abs( x ) );
    Writeln;
 
    Writeln( 'Function   Result for PI = ', Pi:12:10 );
    Writeln( '--------   -----------------------------' );
    Writeln( 'Frac       ', Frac( Pi ):12:9 );
    Writeln( 'Int        ', Int( Pi ):3:1 );
    Writeln( 'Round      ', Round( Pi ) );
    Writeln( 'Trunc      ', Trunc( Pi ) );
    Writeln( 'Exp        ', Exp( Pi ) );
    Writeln( 'Ln         ', Ln( Pi ) );
    Writeln( 'Sqrt       ', Sqrt( Pi ) );
    Writeln( 'Sqr        ', Sqr( Pi ) );
    Writeln( 'Abs        ', Abs( Pi ) );
    Writeln;
 
    Randomize;
    x := Random;
    Writeln;
    Writeln( 'Function   Result for random number ', x );
    Writeln( '--------   --------------------------------------' );
    Writeln( 'Frac       ', Frac( x ):12:9 );
    Writeln( 'Int        ', Int( x ):3:1 );
    Writeln( 'Round      ', Round( x ) );
    Writeln( 'Trunc      ', Trunc( x ) );
    Writeln( 'Exp        ', Exp( x ) );
    IF (x > 0.0) THEN
        Writeln( 'Ln         ', Ln( x ) );
    IF (x >= 0.0) THEN
        Writeln( 'Sqrt       ', Sqrt( x ) );
    Writeln( 'Sqr        ', Sqr( x ) );
    Writeln( 'Abs        ', Abs( x ) );
    Writeln;
 
    i := Random (50);
    Writeln( 'Function   Result for random integer ', i );
    Writeln( '--------   ----------------------------' );
    Writeln( 'Odd        ', Odd( i ) );
    Writeln( 'Exp        ', Exp( i ) );
    Writeln( 'Ln         ', Ln( i ) );
    Writeln( 'Sqrt       ', Sqrt( i ) );
    Writeln( 'Sqr        ', Sqr( i ) );
    Writeln( 'Abs        ', Abs( i ) );
 
END.