Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Standard text messaging rates apply

Arithmetic

1,113
views

Published on

Published in: Business, Technology

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

• Be the first to like this

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

No notes for slide

Transcript

• 1. CS111 Lab Arithmetic Instructor: Michael Gordon
• 2. C++ Arithmetic Operators  + Addition  - Subtraction  * Multiplication  / Division  % Modulus (remainder)  () Parentheses
• 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. 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. 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. 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. Type casting  Reverse example (double to int)  Drops the decimal part  double total = 100.5;  int value = (int) total;  value now equals 100.