# Turbo Pascal 7.0 GuideBuilt-In Arithmetic Functions

The sqrt() function is built into the Pascal programming language. The format of this function is as follows,

`myroot :=sqrt(mysquare)`

The variables myroot and mysquare have been previously declared as real and integer respectively. In this example, mysquare is the parameter sent to the function. The real variable, myroot is assigned the value returned by the function.

FunctionDescriptionParameter TypeReturn Value Type
abs(x)absolute value of x (removes the sign)integer or realsame as x
arctan(x)Inverse tangent of x (in radians)integer or realreal
cos(x)Cosine of x (in radians)integer or realreal
exp(x)Exponential function of x (ex)integer or realreal
ln(x)Natural logarithm of xinteger or realreal
round(x)x rounded to the nearest integerrealinteger
sin(x)sine of x (in radians)integer or realreal
sqr(x)x2integer or realsame as x
sqrt(x)square root of xinteger or realreal
trunc(x)x rounded to its integer partrealinteger

To convert from degrees to radians, multiply by PI/180. To convert from radians to degrees, multiply by 180/PI.

General purpose high-level languages tend not to include an exhaustive list of trigonometric functions. Most other functions can be derived from the ones in the list above.

## Random Numbers

Computers cannot generate actual random numbers. The term pseudorandom is used to reflect the fact that the numbers appear random.

The built-in function RANDOM, returns a pseudorandom number.

 x:= RANDOM random number in the range 0<=x<1 x:= RANDOM(RANGE) random number in the range 0<=x

In order to ensure that the 'random' numbers are not predictable in a program, we use the RANDOMIZE function at the beginning of the program. Random numbers are generated from a seed value. The randomize function changes the seed value for random numbers based on the current value of the computer's clock.

## Example Program

```PROGRAM lottery; VAR a: integer; BEGIN    randomize;    a:= trunc(random(49)) +1;    writeln(a);    readln; END.```

## Exercises

1. Write a program to simulate the throwing of 2 dice.
2. Write a program which allows the user to input the length of 2 sides of a triangle. Use Pythagoras's theorem to find the length of the longest side.