4-ArithmeticINT

4-ArithmeticINT - y yields the remainder after x is divided...

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

View Full Document Right Arrow Icon
Arithmetic in C
Background image of page 1

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

View Full DocumentRight Arrow Icon
Arithmetic in C asterisk ( * ) indicates multiplication percent sign ( % ) denotes the remainder operator In algebra, a times b, can be written as ab. In C, however, ab would be interpreted as a single, two-letter name multiplication must be denoted by using the * operator as in a * b . Parentheses are used in C expressions in the same manner as in algebraic expressions. For example, to multiply a times the quantity b + c we write a * ( b + c ) .
Background image of page 2
Arithmetic in C (Integer Division) All C arithmetic operators are binary operators (operands on each side of the operator). Integer division Integer division yields an integer result. Example: 7 / 4 evaluates to 1 and 17 / 5 evaluates to 3 . remainder operator the remainder operator , % , yields the remainder (as an integer, not a fraction) after integer division. The remainder operator can be used only with integer operands. x %
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: y yields the remainder after x is divided by y . 7 % 4 yields 3 17 % 5 yields 2 . Arithmetic in C (Operator Precedence) rules of operator precedence , are generally the same as those in algebra: Operators in expressions contained within pairs of parentheses are evaluated first. Parentheses are said to be at the highest level of precedence. In cases of nested , or embedded , parentheses , such as ( ( a + b ) + c ) the operators in the innermost pair of parentheses are applied first. Arithmetic in C (Operator Precedence) Multiplication, division and remainder operations are applied first from left to right. Addition and subtraction operations are evaluated next from left to right. ASSIGNMENT Read Chapter 2 (section 2.5 only)...
View Full Document

Page1 / 8

4-ArithmeticINT - y yields the remainder after x is divided...

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

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