Download presentation

Presentation is loading. Please wait.

Published byEzequiel Sorsby Modified over 2 years ago

2
Arithmetic in Pascal (2) Arithmetic Functions

3
Perform arithmetic calculations Gives an argument to the function and it returns the result

4
Some Arithmetic Functions Pascal function Argument type Function type sqr(x)integer or realsame as argument sqrt(x)integer or realreal sin(x)integer or realreal cos(x)integer or realreal ln(x)integer or realreal exp(x)integer or realreal

5
Some Arithmetic Functions Pascal function Argument type Function type random(x)integer abs(x)integer or realsame as argument round(x)realinteger trunc(x)realinteger

6
sqr(x) Return the square of the argument The type of the result is the same as the argument D := sqr(2) D = 4

7
sqrt(x) Return the square root of the argument The type of the result is always real The function type is real even when the result is a rounded number D := sqrt(9) D = 3.0

8
sin(x), cos(x) Return the sine and cosine of the argument The type of the result is always real The argument should be in radians, not degree Use Degree * Pi / 180 to calculate the radians

9
ln(x), exp(x) Return the value of ln and exp like the same function in your calculator The type of the result is always real X y := exp( y * ln(x) )

10
random(x) Return a random number between 0 and the argument – 1 The type of the result is integer Exception When you use random with no argument, it returns a number of type real ranged from 0 to 1 (but not include 1)

11
random(x) (cont.) Try to write a program to generate three random number Run the program for a few times Something strange !! Try to add a line randomize; before using random(x) This procedure randomize the random number generator

12
abs(x) Return the absolute value (positive value) of the argument The type of the result is the same as the type of input argument

13
round(x) Return the value of the argument rounded to the nearest integer The type of the result is always integer round(10.5) = 11 round(10.4) = 10 round(-10.5) = -11 round(-10.4) = -10

14
trunc(x) Return the value of the argument rounded to the nearest integer towards zero Or we could say everything after the decimal point is truncated trunc(10.9) = 10 trunc(-10.9) = 10

Similar presentations

OK

Warm- Up 1. Find the sine, cosine and tangent of A. 2. Find x. 12 x 51° 6 8 10 A.

Warm- Up 1. Find the sine, cosine and tangent of A. 2. Find x. 12 x 51° 6 8 10 A.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Marketing mix ppt on nokia phones Ppt on forward contract accounting Ppt on conservation of wildlife and natural vegetation of africa Ppt on causes of 1857 revolt leaders Ppt on classical economics unemployment Ppt on transportation in plants and animals Training ppt on team building Ppt on charge coupled device manufacturer Ppt on power grid failure solar Ppt on tata company profile