4-ArithmeticINT

# 4-ArithmeticINT - y – yields the remainder after x is...

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

Arithmetic in C

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

View Full Document
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 ) .
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 %

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

View Full Document

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

View Full Document

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.

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

## This document was uploaded on 11/07/2010.

### Page1 / 8

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

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

View Full Document
Ask a homework question - tutors are online