Lexington High School Mathematics Math Dept. Front Page  | Student Links  | Family Links 
C++ courses Intro. Prog. I  | Intro. Prog. II  | AP Comp. Sci.  | C++ Info Page 

Math Operations Reference Sheet

OPERATOR PRECEDENCE AND GROUPING
Order Operator Grouping Description
First    (  ) left to right Parentheses
     *   Multiplication
      /   Division
     %   Modulo
     +   Addition
Last     -   Subtraction

[Modulo is a remainder function so 6%3 = 0 because 3 goes into 6 twice with no remainder but 7%3 = 1 because 3 goes into 7 twice with a remainder of 1.]

Below is an example of an equation, followed by each intermediate result, until the final result is obtained.

7 * 10 - 5 % 3 * 4 + 9
70 - 5 % 3 * 4 + 9
70 - 2 * 4 + 9
70 - 8 + 9
62 + 9
71

It is usually good practice to put in some parentheses to enhance the readability of the equation. The reader should not have to struggle with your equation if a set of parentheses or two would eliminate any confusion. Parentheses can also be used to change the usual order of evaluation of an expression as determined by precedence and grouping(associativity). Consider the following changes in the example above: .

(7 * (10 - 5) % 3) * 4 + 9
(7 * 5 % 3) * 4 + 9
(35 % 3) * 4 + 9
2 * 4 + 9
8 + 9
17

There are also a number of functions provided by the math library. To access the functions in your program you must include math.h at the beginning of your program. Each of the functions takes one or more parameters of type double and returns a value of type double.

MATH LIBRARY FUNCTIONS
Function Description
sin(x) Sine of x (in radians)
cos(x) Cosine of x (in radians)
tan(x) Tangent of x (in radians)
asin(x) Inverse sine of x (function return in radians)
acos(x) Inverse cosine of x (function return in radians)
atan(x) Inverse tangent of x (function return in radians)
sinh(x) Hyperbolic sine of x
cosh(x) Hyperbolic cosine of x
tanh(x) Hyperbolic tangent of x
exp(x) Exponential function ex
log(x) Natural logarithm of x
log10(x) Base 10 logarithm of x
pow(x,y) x raised to the power of y
sqrt(x) Square root of x
ceil(x) Smallest integer greater than or equal to x
floor(x) Largest integer less than or equal to x