1 / 13

Arithmetic in Pascal (2)

Arithmetic in Pascal (2). Arithmetic Functions. Arithmetic Functions. Perform arithmetic calculations Gives an argument to the function and it returns the result. Some Arithmetic Functions. Some Arithmetic Functions. sqr(x). Return the square of the argument

stacy-potts
Download Presentation

Arithmetic in Pascal (2)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Arithmetic in Pascal (2) Arithmetic Functions

  2. Arithmetic Functions • Perform arithmetic calculations • Gives an argument to the function and it returns the result

  3. Some Arithmetic Functions

  4. Some Arithmetic Functions

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

  6. 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

  7. 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

  8. 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 • Xy := exp( y * ln(x) )

  9. 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)

  10. 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

  11. 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

  12. 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

  13. 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

More Related