1_Review_Ch_3-1

# 1_Review_Ch_3-1 - CIS 15AG 1 Review Chapter 3 Structure of...

This preview shows pages 1–2. Sign up to view the full content.

CIS 15AG Review Chapter 3: Structure of a C Program: Expressions and Statements Expression – a sequence of operands and operators that reduces to a single value, such as: 40 + 50 or 5 + 12 / 3 Division and natural numbers – if num and d are natural numbers, with d non-zero, there exist unique integers q and r such that num = q · d + r , and 0 r < d . num dividend , d divisor , q quotient , r remainder . For instance, when dividing 9 by 4 , the quotient is 2 and the remainder is 1 : 9 = 2·4 + 1 Division and integers – quotient and remainder are not unique. Examples: Dividend Quotient Divisor Remainder 9 / 4 9 = 2 · 4 + 1 -9 / 4 -9 = (-2) · 4 + (-1) -9 = (-3) · 4 + 3 9 / -4 9 = (-2) ·(-4)+ 1 9 = (-3) ·(-4)+ (-3) -9 / -4 -9 = 2 ·(-4)+ (-1) -9 = 3 ·(-4)+ 3 In number theory, usually the positive remainder is chosen, but not in programming. Some programming languages choose the remainder with the same sign as the dividend (Pascal, C99), others with the same sign as the divisor (Perl, Python). Arithmetic Operators + add 9 + 4 - subtract 9 - 4 4 - 9 * multiply 9 * 4 / divide 9 / 4 => 2 // Integer result if both operands are integer 9 / 4.0 => 2.25 9.0 / 4 => 2.25 9.0 / 4.0 => 2.25 // Floating-point result if either operand is a // floating-point number % modulus - produces the remainder 8 % 4 0 9

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 3

1_Review_Ch_3-1 - CIS 15AG 1 Review Chapter 3 Structure of...

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

View Full Document
Ask a homework question - tutors are online