0% found this document useful (0 votes)
25 views

Arithmetic Logical Relational-operatorsCONT

The document discusses different types of operators in programming - arithmetic, logical, and relational operators. It provides examples of common arithmetic operators like addition, subtraction, multiplication, and division. Logical operators help control program flow and take decisions based on conditions. Relational operators allow comparisons between values, like determining if one value is greater than, less than, equal to, or not equal to another value. Examples are provided for operators of each type.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Arithmetic Logical Relational-operatorsCONT

The document discusses different types of operators in programming - arithmetic, logical, and relational operators. It provides examples of common arithmetic operators like addition, subtraction, multiplication, and division. Logical operators help control program flow and take decisions based on conditions. Relational operators allow comparisons between values, like determining if one value is greater than, less than, equal to, or not equal to another value. Examples are provided for operators of each type.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Arithmetic, Logical

ANd Relational
Operators
WHAT IS OPERATOR?

✗ In programming, operator is a special


symbol that tells the computer to
perform mathematical, relational or
logical operation to produce a desired
output.

2
INPUT OPERATOR OUTPUT

Fig 1. Role of a operator in A computer program.

3
1
ARITHMETIC OPERATORS
Computer programs are widely used
for mathematical calculations. We can
write a computer program which can
do simple calculation like adding two
n u m bers a n d w e ca n a lso w r i t e a
program, which can solve a complex
equation.

5
ARITHMETIC OPERATORS IN JAVASCRIPT

6
Adding
The addition operator (+) adds numbers.

Example:

let x = 5;
let y = 2;
let z = x + y;
7
Subtracting
The subtraction operator (-) subtracts
numbers.

Example:
let x = 5;
let y = 2;
let z = x - y;
8
multiplying
The multiplication operator (*) multiples
numbers.

Example:
let x = 5;
let y = 2;
let z = x*y;
9
dividing
The division operator (/) divides numbers.

Example:
let x = 5;
let y = 2;
let z = x / y;

10
remainder
The modulus operator (%) returns the
division remainder.

Example:
let x = 5;
let y = 2;
let z = x % y;
11
incrementing
The increment operator (++) increments
numbers.
Example:
let x = 5;
x++;
let z = x;

12
decrementing
The decrement operator (--) decrements
numbers.
Example:
let x = 5;
x--;
let z = x;

13
exponentiation
The exponentiation operator (**) raises the
first operand to the power of the second
operand.
Example:
let x = 5;
let z = x ** 2;

14
exponentiation
The exponentiation operator (**) raises the
first operand to the power of the second
operand.
Example:
let x = 5;
let z = x ** 2;

15
operator precedence
Operator precedence describes the order
in which operations are performed in an
arithmetic expression.

let x = 100 + 5 * 3;

16
ASSIGNMENT OPERATORS
Are operators that assign a value to a
variable.

Let x = 3; // x contains the value 3


Let y = 4; // y contains the value 4
x = y; // x now contains the same
value y contains, 4
17
18
LET US TRY!

19
ACTIVITY 1:
Indicate the correct arithmetic operators in
each statement.

1. Multiple 10 with 5, and alert the result:

alert (10 * 5);

20
ACTIVITY 1:
Indicate the correct arithmetic operators in
each statement.

1. Multiple 10 with 5, and alert the result:

alert (10 * 5);

21
ACTIVITY 1:
Indicate the correct arithmetic operators in
each statement.

2. Divide 20 with 10, and alert the result:

alert (20 / 10);

22
ACTIVITY 1:
Indicate the correct arithmetic operators in
each statement.

2. Divide 20 with 10, and alert the result:

alert (20 / 10);

23
ACTIVITY 1:
Indicate the correct arithmetic operators in
each statement.

3. Alert the remaider when 15 is divided


by 9:
alert (15 % 9);

24
ACTIVITY 1:
Indicate the correct arithmetic operators in
each statement.

3. Alert the remaider when 15 is divided


by 9:
alert (15 % 9);

25
ACTIVITY 1:
Indicate the correct arithmetic operators in
each statement.
4. Use the correct assignment operator that will
result in x being 15 (same as x = x + y)
x=10;
y=5;
x =+ y;

26
ACTIVITY 1:
Indicate the correct arithmetic operators in
each statement.
4. Use the correct assignment operator that will
result in x being 15 (same as x = x + y)
x=10;
y=5;
x =+ y;

27
ACTIVITY 1:
Indicate the correct arithmetic operators in
each statement.

5. Use the correct assignment operator that will


result in x being 50 (same as x = x * y).
x=10;
y=5;
x *= y;
28
ACTIVITY 1:
Indicate the correct arithmetic operators in
each statement.

5. Use the correct assignment operator that will


result in x being 50 (same as x = x * y).
x=10;
y=5;
x *= y;
29
LOgical OPERATOR
help us take decisions
based on certain
conditions.

30
LOGICAL OPERATORS

Logical operators are mainly used to


control program flow. Usually, you will
find them as part of an if, while, or some
other control statement. 

31
In two or three columns

32
Example
let x = 1;
if (x > 0) alert( 'Greater than zero!' );
let hour = 9;
if (hour < 10 || hour > 18) {
alert( 'The office is closed.' );
}

33
Example
let x = 1;
if (x > 0) alert( 'Greater than zero!' );
let hour = 9;
if (hour < 10 || hour > 18) {
alert( 'The office is closed.' );
}

34
RELATIONAL OPERATORS
They allow us to
compare numeric and
char values to
determine if one is
greater than, less than,
equal to, or not equal
to another.

35
RELATIONAL OPERATORS

36
RELATIONAL OPERATORS

37
COMPARISON OPERATORS

38

You might also like