03 Lesson - Basic Input Output
03 Lesson - Basic Input Output
Minds On…
Table Source
Note: In this course, we’ll be using mostly int and double as numeric data types.
Numeric Operators
The operators for numeric data types include the standard arithmetic operators: addition (+),
subtraction (–), multiplication (*), division (/), and remainder (%), as shown in Table 2.2.
The operands are the values operated by an operator.
Modulus is very useful in programing. For example, an even number % 2 will always result in 0 and an
off number % 2 will always result in 1. So you use this property to determine whether a number is
even or odd.
If today is Saturday, it will be Saturday again in 7 days. Suppose you and your friends are going to
meet in 10 days. What day is in 10 days? You can find that day is Tuesday using the following
expression:
5
Exponent Operations
To write bn in C++, we use Math.pow(b, n). For example,
Note that you could also use Math.sqrt(4.0) to compute the same result as above.
Assessment
1. Which of the following are the same as 52.534?
9. Which of the following data types require the most amount of memory?