Upcoming SlideShare
×

# Arithmetic

1,149
-1

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
1,149
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
6
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Arithmetic

1. 1. CS111 Lab Arithmetic Instructor: Michael Gordon
2. 2. C++ Arithmetic Operators  + Addition  - Subtraction  * Multiplication  / Division  % Modulus (remainder)  () Parentheses
3. 3. Order of Operations  ()  * / %  + -  (4 + 2) / 2 + 4 = ???  Operation in () first: 4+2=6  Division next: 6 / 2 = 3  Last addition, 3 + 4 = 7
4. 4. Integer and Decimal Division  Division of two integers drops the decimal:  5 / 2 = 2 (not 2.5)  4 / 2 = 2  Division involving a double type, will result in a double result (with decimal)  5 / 2.0 = 2.5  4 / 2.0 = 2  One or both numbers must be a double  Same rules apply to addition, subtraction and multiplication.
5. 5. Data Types and Order  Sample operations and resulting data types:  6.0 + 5 / 2  Result of first operation: int  Result of second operation: double  • 5 + 5 / 2.0  Result of first operation: double  Result of second operation: double
6. 6. Type casting  Type casting changes one type to another.  For example if you want a double type result of integer division, you can do this:  double result = (double) 5 / 2  result now equals 2.5
7. 7. Type casting  Reverse example (double to int)  Drops the decimal part  double total = 100.5;  int value = (int) total;  value now equals 100.
1. #### A particular slide catching your eye?

Clipping is a handy way to collect important slides you want to go back to later.