The Pascal Programming Language

Arithmetic Functions Example Program


Click below to go directly to a specific section:
Description | Source Code | Sample Run | Program Notes

Description

This program demonstrates Pascal's use of several arthmetic functions such as; Square Root(Sqrt), Square(Sqr), Absolute Value(Abs), Truncation(Trunc) and Rounding(Round).


Source Code

program ArithFunc;
  const
    Sentinel =0.0;
  var
    X:Real;
begin    
   writeln('After each line enter a real number or 0.0 to stop');
   writeln;
   writeln('X', 'Trunc(x)' :16, 'Round(X)' :10, 'Abs(X)' :10,
           'Sqr(X)' :10, 'Sqrt(Abs(X))' :15); 
   readln (X);
   while X <> Sentinel do
     begin
       writeln (Trunc(X) :17, Round(X) :10, Abs(X) :10:2, 
                 Sqr(x) :10:2, Sqrt(Abs(X)) :10:2);
       readln(X);
     end
end.    


Sample Run

After each line enter a real number or 0.0 to stop
X        Trunc(X)  Round(X)     Abs(X)    Sqr(X)   Sqrt(Abs(X))
5.7             5         6       5.70     32.49      2.38
0.0


Program Notes

This program was tested and run using Turbo Pascal 7.0 complier from Borland..


[Back] [Home]

Last modified: 06:14 PM on 11/23/1996