Chapter4b-Expression and Operator
Chapter4b-Expression and Operator
Logical Expression
Introduction to Expression
Expressio
n
2x+3-z=y
Process involves in money withdrawal scenario
Expression in C?
Introduction to Expression
Introduction to Expression
Combination of more than one variable
or constant (operand) which separated
by operator
Operand
Example : x+3-z
Operator
Consists of:
using
Arithmetic
Operator
Unary Binary
Operator Operator
Unary Operator
Example : A + Z
Use operator
symbol =
Double Compound
assignment assignment
statement statement
Assignment Statement
Compound Assignment Statement
Function
Operator
3*4/2+ 2
12 /2+ 2
6 + 2
Function Purpose
sqrt(x) Compute the non-negative
square root of x
pow(x,y) Compute x raised to the power y
cos(x) Compute the cosine of x
(measured in radians)
sin(x) Compute the sine of x (measured
in radians)
tan(x) Compute the tangent of
x(measured in radians)
Mathematic Library Function
Example:
#include
<stdio.h> Output?
#include
<math.h>
Void main()
{
int x =
16, y;
Relational Expression Relational
use
operator
Consists of
1. variable vs variable
2. variable vs constant Combination of
3. constant vs constant more than one
statement
Produce
int a = 6, b = 1, c = -
2
1. a + b == c
2. a != b Answer:
0 or 1?
3. b < c
4. b + c <= a
Relational Expression Example 2
int a = 10, b = 3, c =
7
(a+b >= 3*c == (a != 2*c+b)
0 == 1
0 (false)
Relational
Expression
– example
program
Logical Expression
use Logical operator
Consists of
Example 1
1 1
Logical Expression
Example 2
Given a = 3, b = 4;
1
Logical
Expression
– example
program