4 - ICS103 Programming in C Lecture 4: Data Types,...

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

View Full Document Right Arrow Icon
1 ICS103 Programming in C Lecture 4: Data Types, Operators & Expressions
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Outline C Arithmetic Expressions Operators Data Type of Expression Mixed-Type Assignment Statement Type Conversion through Cast Expressions with Multiple Operators Writing Mathematical Formulas in C Programming Style
Background image of page 2
3 Why Arithmetic Expressions To solve most programming problems, you will need to write arithmetic expressions that manipulate type int and double data. The next slide shows all arithmetic operators. Each operator manipulates two operands , which may be constants, variables, or other arithmetic expressions. Example 5 + 2 sum + (incr* 2) (B/C) + (A + 0.5)
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 C Operators Arithmetic Operator Meaning Examples + ( int , double ) Addition 5 + 2 is 7 5.0 + 2.0 is 7.0 - ( int , double ) Subtraction 5 - 2 is 3 5.0 - 2.0 is 3.0 * ( int , double ) Multiplication 5 * 2 is 10 5.0 * 2.0 is 10.0 / ( int , double ) Division 5 / 2 is 2 5.0 / 2.0 is 2.5 % ( int ) Remainder 5 % 2 is 1
Background image of page 4
Division : When applied to two positive integers, the division operator (/) computes the integral part of the result by dividing its first operand by its second. For example 7.0 / 2.0 is 3.5 but the but 7 / 2 is only 3 The reason for this is that C makes the answer be of the same type as the operands. Remainder : The remainder operator (%) returns the integer remainder of the result of dividing its first operand by its second. Examples: 7 % 2 = 1, 6 % 3 = 0 The value of m%n must always be less than the divisor n. / is undefined when the divisor (second operator) is 0.
Background image of page 5

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

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

This note was uploaded on 05/09/2010 for the course ICS 103 taught by Professor Baleh during the Spring '10 term at Abilene Christian University.

Page1 / 19

4 - ICS103 Programming in C Lecture 4: Data Types,...

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

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