Arithmetic Operations

Arithmetic operators

C++ has the following operators:

Operator Purpose Example x
+ addition x=5+3; 8
+ addition x=5+3.0; 8.0
- minus x=5-3; 2
- minus x=5-3.0; 2.0
* multiplication x=5*3; 15
* multiplication x=5*3.0; 15.0
/ division x=9/2; 4
/ division x=9/2.0; 4.5
% remainder x=14%3; 2

An actual program would not use a statement such as X=5+3; it would save time to simply use X=8. An actual program would be more likely to use variables: X=Y+Z; for example.

Note that there is a times, or multiplication, operator: *. In algebra, variables are always a single letter, XY in algebra means X times Y. In programming, variables can be several letters, and we could not be sure whether XY meant X times Y or a variable called XY.

Notice that operations on two integers results in an integer. If we divide 9/2 we get just 4. If we want 4.5 we must make one of the operands a double or float.

Remainder: %

The % operator is used to find the remainder. Before children learn about decimal numbers, they may give the answer to division problems as: "17 divided by 5 is 3 with a remainder of 2" Note that 17/5 results in 3, while 17 % 5 results in 2.

Please study the material at each of the links below.

  1. Operators
  2. The % operator: remainder
  3. finding dozens
  4. Order of operations
  5. Drill: Order of operations
  6. calculate grade
  7. Algebra to code
  8. Math Functions
  9. How many busses?
Like us on Facebook:

OER: Open Educational Resource
Creative Commons License Author: Janet E. Joy; Publisher:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
Creative Commons Attribution-NonCommercial 4.0 International License
Last modified: May 18 2017 13:56:51.