1_Review_Ch_3-1

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online