
COMMON FUNCTIONS
The Pascal language provides a range of functions to perform
data transformation and calculations. The following section
provides an explanation of the commonly provided functions,
- ABS
The ABSolute function returns the absolute value of either an integer
or real, eg,
ABS( -21 ) returns 21
ABS( -3.5) returns 3.5000000000E+00
- COS
The COSine function returns the cosine value, in radians, of an
argument, eg,
COS( 0 ) returns 1.0
- EXP
The exponential function calculates e raised to the power of a number, eg,
EXP(10 ) returns e to the power of 10
There is no function in Pascal to calculate expressions such as an, ie,
23 is 2*2*2 = 8
These are calculated by using the formula
an = exp( n * ln( a ) )
- LN
The logarithm function calculates the natural log of a number greater
than zero.
- ODD
The odd function determines when a specified number is odd or even,
returning true when the number is odd, false when it is not.
- ROUND
The round function rounds its number (argument) to the nearest integer.
If the argument is positive
rounding is up for fractions greater than or equal to .5
rounding is down for fractions less than .5
If the number is negative
rounding is down (away from zero) for fractions >= .5
rounding is up (towards zero) for fractions < .5
- SIN
The sine function returns the sine of its argument, eg,
SIN( PI / 2 ) returns 1.0
- SQR
The square function returns the square (ie the argument multiplied
by itself) of its supplied argument,
SQR( 2 ) returns 4
- SQRT
This function returns {always returns a real} the square root of
its argument, eg,
SQRT( 4 ) returns 2.0000000000E+00
- TRUNC
This function returns the whole part (no decimal places) of a real number.
TRUNC(4.87) returns 4
TRUNC(-3.4) returns 3
PROGRAM FOURTEEN
Given the following list of wages stored in an array,
210.33 119.78 191.05 222.94
calculate the total breakdown of required coins (ignore dollars) into
50c, 20c, 10c, 5c, 2c, and 1c pieces.
Click here for answer
Copyright B Brown/P Henry/CIT, 1988-1997. All rights reserved.
