Module 1 Q2W1 4
Module 1 Q2W1 4
Computer Programming
Module 2: Quarter 1(Week 3-4)
OBJECTIVES
At the end of this lesson, the learners should be able to:
Demonstrate the use of the different types of operators in basic
programming.
1. Understand the meaning of operator
2. Perform mathematical, relational and logical operations
3. Differentiate the Types of Identifiers
VOCABULARY
What’s New?
- Read Lesson Information closely and find out how much you can remember.
Then do Self-Check 1.1. Activity and Task Sheet 1.1 to know how much you
have learned.
Watch this!
GRADE-10
SCIENCE, TECHNOLOGY and ENGINEERING CP
Lesson Information 1.1
An Operator in a programming language is a symbol that tells the compiler or
interpreter to perform specific mathematical, relational or logical operation and
produce final result.
Arithmetic Operations
Arithmetic operators are used to carry out arithmetic operations in BASIC. These are
the symbols used to perform any mathematical operations between 2 or more
operands. These operators are executed according to their hierarchy or what is called
precedence rule. Table 16.1 below shows these operators according to their
hierarchy.
Table 6.1: Hierarchy of Arithmetic Operators
Operation Operators used Examples
Parentheses () (a+b)*c
Exponentiation ^ M = a + (b^4)
Multiplication * a*b=b*a
Division (Real) / 7/3=2.5
Modulo (Remainder) % 7%3=1
Addition + a + b=b + a
Subtraction - 9 – 6 =3
RELATIONAL OPERATORS
Consider a situation where we create two variables and assign them some values as
follows −
A = 20
B = 10
Here, it is obvious that variable A is greater than B in values. So, we need the help of
some symbols to write such expressions which are called relational expressions. If we
use C programming language, then it will be written as follows −
(A > B)
Here, we used a symbol > and it is called a relational operator and in their simplest
form, they produce Boolean results which means the result will be either true or false.
Similarly, a programming language provides various relational operators. The
following table lists down a few of the important relational operators available in C
programming language. Assume variable A holds 10 and variable B holds 20, then −
> Checks if the value of left operand is greater (A > B) is not true.
than the value of right operand, if yes then
condition becomes true.
< Checks if the value of left operand is less than (A < B) is true.
the value of right operand, if yes then condition
becomes true.
>= Checks if the value of left operand is greater (A >= B) is not true.
than or equal to the value of right operand, if yes
then condition becomes true.
<= Checks if the value of left operand is less than or (A <= B) is true.
equal to the value of right operand, if yes then
condition becomes true.
The if statement is used to check a condition and if the condition is true, then the body
of if statement is executed, otherwise the body of if statement is skipped.
Logical Operators
Logical operators are very important in any programming language and they help
us take decisions based on certain conditions. Suppose we want to combine the
result of two conditions, then logical AND and OR logical operators help us in
producing the final result.
The following table shows all the logical operators supported by the C language.
Assume variable A holds 1 and variable B holds 0, then −
Self-Check 1.1
A. IDENTIFICATION: Write your answer on the space provided before each number.
_____________1. What type of operator is used to evaluate 2 or more values or
variables and the result is True or False?
_____________2. What symbol represent the “Logical AND” operator?
_____________3. On what programming statement do the Relational Operators is
being used?
_____________4. What do you call to this symbol ==?
_____________5. This is a symbol that performs mathematical, relational and even
logical operations and produced final result.
TITLE:
WRITTEN TEST
PERFORMANCE OBJECTIVE: Given the Task Sheet 1.1; Look for the attached Learning
Activity Sheet 1.
ANSWER KEY