operator - Chapter 3 Operators and Expressions Outline...

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

View Full Document Right Arrow Icon
Chapter 3 Operators and Expressions Outline Arithmetic Operators Relational Operators Logic Operators Bitwise Operators Assignment Operators Increment and Decrement Operators Conditional Operator Cast Operators Comma Operator Sizeof Operator Precedence and Associativity of Operators
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 Operators • There are five arithmetic operators: 1) + Addition 2) - Subtraction 3) * Multiplication 4) / Division 5) % Modulus The multiplication operator * is needed for multiplication. • The result of the % operator is the remainder. If the value of the second operand is zero, the behavior is undefined. • The operands of the % operator shall have integer type. Example: > int i = 5 > 5*i 50 > 19/5 3 > 19%5 4 > 19.0/5 3.8000 > 19/5.0 3.8000
Background image of page 2
A data type that occupies less memory can be converted to a data type that occupies more memory space without loss of any information. The order of real numbers ranges from char, short, int, float, to double. The algorithms and resultant data types of operations depend on the data types of the operand. For binary operations, such as addition, subtraction, multiplication, and division, the resultant data type will take the higher order data type of two operands. For example, the addition of two float numbers will result in a float, while the addition of a float and a double will result in a double.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Note: there is no exponential operator in C. Mathematical function pow (x, y) can be used to calculate the exponential expression x y . Mathematical function sqrt (x) can be used to calculate the square root of variable x. These functions are declared inside header file math.h Example: /* File: powsqrt.c */ #include <stdio.h> #include <math.h> int main() { double p, x = 2, y = 3; p = pow(x,y); printf("pow(2,3) = %f\n", p); printf(“sqrt(2) = %f\n", sqrt(x)); return 0; } Output: pow(2,3) = 8.000000 sqrt(2) = 1.414214
Background image of page 4
Sample Problem A quadratic (second order polynomial) equation ax 2 + bx + c = 0 can be solved by the formulas Note: The square root of a negative value is a complex number.
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 04/16/2008 for the course MATH 21A taught by Professor Osserman during the Fall '07 term at UC Davis.

Page1 / 23

operator - Chapter 3 Operators and Expressions Outline...

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