course content

Course Content

Introduction to C++

A Little MathA Little Math

The following five mathematical operators (+, -, *, / and %) are used to perform mathematical operations:

cpp

main.cpp

The modulo operator (%) returns the remainder of the normal division.

The division operator (/) returns only the integer part, discarding the remainder part. For example, 10 / 3 = 3, not 3.333… To get the expected result of division (10 / 3 = 3.333), one of the operands must be a double or float type:

cpp

main.cpp

The sum operator is the only mathematical operator the applies to string (concatenation):

cpp

main.cpp

There are also comparison operators (>, <, <=, >=). They are used if you need to compare some value with a specific range numerically:

cpp

main.cpp

1. 15 / 4 = ?
2. 8 % 6 = ?

question-icon

15 / 4 = ?

Select the correct answer

question-icon

8 % 6 = ?

Select the correct answer

Section 3.

Chapter 2