Professional Documents
Culture Documents
Arithmetic Expression
Sub topics
Relation Expression
Logical Expression
Introduction to Expression
Expression
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
• postfix increment: In this method, the operator follows the operand (e.g.,
a++). The value operand will be altered after it is used.
Prefix vs Postfix
• Decrement: It is used to decrement the value of the variable by 1.
The decrement can be done in two ways:
• prefix decrement: In this method, the operator precedes the operand
(e.g., – -a). The value of the operand will be altered before it is used.
• postfix decrement: In this method, the operator follows the operand (e.g.,
a- -). The value of the operand will be altered after it is used.
Unary Operator Example 1
Unary Operator Example 2
Unary Operator Example 3
Binary 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>
#include <math.h> Output?
Void main()
{
int x = 16,
y;
y=
sqrt(x);
Exercise
Exercise
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;
0 !(0)
1
Logical
Expression –
example
program
Exercise