Lecture-3_Logical operators

Lecture-3_Logical operators - Operators result is always an...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Computer Science I - Martin Hardwick Lecture 5 -- 1 Arithmetic Expressions With Integers Operators: result is always an integer Symbol Name Example Value (x = 10, y=3) + addition x + y 13 subtraction x – y 7 *multiplication x * y 30 / quotient x / y 3 % remainder x % y 1 unary minus –x -10 + unary plus +x 10 You can string the operators together to build longer expressions. use parentheses to specify order of operations precedence (after sub-expressions in parentheses) – first: unary plus and minus from right to left – second:  *, / and % from left to right – third:  + and – from left to right
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Computer Science I - Martin Hardwick Lecture 5 -- 2 Arithmetic Expression Examples 12 + 2 * 5 - 8 / 3 + 6 10 2 22 20 26 -2 * 3 * (4 + 5) % 10 + -3 -3 -2 9 -6 -54 -4 -7
Background image of page 2
Computer Science I - Martin Hardwick Lecture 5 -- 3 Arithmetic Exprs With Doubles Arithmetic expressions with real numbers (numbers with decimal points) work the same way as with integers, with a few exceptions: there is no remainder operator (“%”) the “/” operator means “divide”, computing the answer  to many decimal places the result is a real value rather than an integer value Important: Real values are approximate and may contain errors in the last few digits. about 7 digits of accuracy for type float (one word) about 14 digits of accuracy for type double (two  words) so programmers today nearly always use doubles Real values are often represented using scientific notation. Example:     1.857409 x 10 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Computer Science I - Martin Hardwick Lecture 5 -- 4 Mixed Mode Arithmetic Expressions Arithmetic expressions both integers and doubles can get tricky. if both operands are integers, integer arithmetic is used
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/04/2011 for the course CS 2400 taught by Professor Richie during the Spring '11 term at Rensselaer Polytechnic Institute.

Page1 / 14

Lecture-3_Logical operators - Operators result is always an...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online