Professional Documents
Culture Documents
Computer
Programming
Quarter III – Module 1:
Arithmetic, Logical and Relational Operators
"Designed by macrovector /
Freepik"
Computer Programming – Grade 10
Self-Learning Module
First Edition, 2020
Republic Act 8293, section 176 states that: No copyright shall subsist in any work
of the Government of the Philippines. However, prior approval of the government agency or
office wherein the work is created shall be necessary for exploitation of such work for profit.
Such agency or office may, among other things, impose as a condition the payment of
royalties.
Borrowed materials (i.e., songs, stories, poems, pictures, photos, brand names,
trademarks, etc.) included in this module are owned by their respective copyright holders.
Every effort has been exerted to locate and seek permission to use these materials from
their respective copyright owners. The publisher and authors do not represent nor claim
ownership over them.
continue your studies and learn while at home. Activities, questions, directions,
exercises, and discussions are carefully stated for you to understand each lesson.
Each SLM is composed of different parts. Each part shall guide you step-by-
step as you discover and understand the lesson prepared for you.
At the end of each module, you need to answer the test to self-check your
learning. Answer keys are provided for each activity and test. We trust that you will be
In addition to the material in the main text, Notes to the Teacher are also
provided to our facilitators and parents for strategies and reminders on how they can
Please use this module with care. Do not put unnecessary marks on any part of
this SLM. Use a separate sheet of paper in answering the exercises and tests. And
If you have any questions in using this SLM or any difficulty in answering the
Thank you.
Explore
After going through this self-learning module, you are expected to:
program.
output. There are many types of operators in the computer programming world,
some can only be found on specific programming language, but these three is
common to all.
It needs an input value such as numbers and letters to function properly. The
operator works like the brain of a human being that can tell the difference
between two objects, intelligent enough to make decision based on the values
Learn
processes to be followed are represented by symbols. There are actually two kinds
Now, we will learn what are the different types of operators in computer
The farmer's challenge was to carry himself and his purchases to the far
bank of the river, leaving each purchase intact. How did he do it?
Where you able to solve the problem of the farmer? Do you know that you can
Here is a program that the farmer can use to check which of his purchased item can be
Here’s a program flowchart that you can follow when you start coding later.
Item Value Legend:
start Cabbage = 1
Goat = 2
Wolf = 3
Which items will you
leave behind?
Enter Item1
Enter Item2
F F
Item1 > Item2 (Item2 -1)
“Your Items
= Item1
are safe”
T
T
F
(Item1 -1) = “Your Items “Item2 will eat
Item2 are safe” Item1”
stop
Arithmetic Operators
can write a computer program which can do simple calculation like adding two
numbers (2 + 3) and we can also write a program, which can solve a complex
equation like P(x) = x4 + 7x3 - 5x + 9. In the expression 2+3, we are aware that
the numbers 2 and 3 are operands, and the + sign is an operator. Similar
1. 2 + 3
4 3
2. P(x) = x + 7x - 5x + 9.
language. The plus and minus signs used in these expressions are called
arithmetic operators and the values used in these expressions like 2, 3, x, etc.,
are called operands. In their simplest form, such expressions produce numerical
results.
following table lists down a few of the important arithmetic operators available
then
- Subtracts second operand from the first A–B will give -10
* Multiplies both operands A*B will give 200
#include <stdio.h>
int main() {
int a, b, c;
a = 10;
b = 20;
c = a + b;
printf( "Value of c = %d\n", c);
c = a - b;
printf( "Value of c = %d\n", c);
c = a * b;
printf( "Value of c = %d\n", c);
c = b / a;
printf( "Value of c = %d\n", c);
c = b % a;
printf( "Value of c = %d\n", c);
}
Value of c = 30
Value of c = -10
Value of c = 200
Value of c = 2
Value of c = 0
Simple example in Javascript Programming
var x = 5;
var y = 2;
var z = x - y;
console.log(z);
// declare variables
int a = 12, b = 5;
// addition operator
// subtraction operator
// multiplication operator
// division operator
Dim x As Integer
x = 67 + 34
x = 32 - 12
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
The following table shows all the logical operators supported by the C language.
true.
true.
Try the following example to understand all the logical operators available
in C programming language
#include <stdio.h>
int main() {
int a = 1;
int b = 0;
if ( a && b ) {
When you compile and execute the above program, it produces the following results:
class Main {
public static void main(String[] args) {
// && operator
System.out.println((5 > 3) && (8 > 5)); // true
System.out.println((5 > 3) && (8 < 5)); // false
// || operator
System.out.println((5 < 3) || (8 > 5)); // true
System.out.println((5 > 3) || (8 < 5)); // true
System.out.println((5 < 3) || (8 < 5)); // false
// ! operator
System.out.println(!(5 == 3)); // true
System.out.println(!(5 > 3)); // false
}
}
Relational Operators
A = 20
B = 10
(A > B)
Operators
> Checks if the value of left operand is greater (A > B) is not true
becomes true.
>= Checks if the value of left operand is greater (A >= B) is not true.
<= Checks if the value of left operand is less than (A <= B) is true.
!= (A != B) is true
Checks if the values of two operands are equal
or not, if values are not equal then condition
becomes true.
module, but to give you an idea, we use if statement to check a condition and if
the condition is true, then the body of if statement is executed, otherwise the
int main() {
int a, b;
a = 10;
b = 20;
function myFunction() {
age = document.getElementById("age").value;
// create variables
int a = 7, b = 11;
// value of a and b
System.out.println("a is " + a + " and b is " + b);
// == operator
System.out.println(a == b); // false
// != operator
System.out.println(a != b); // true
// > operator
System.out.println(a > b); // false
// < operator
System.out.println(a < b); // true
// >= operator
System.out.println(a >= b); // false
// <= operator
System.out.println(a <= b); // true
}
}
Engage
INSTRUCTIONS:
1. Write a program using any of the operators in our lesson, to accept 3 non-
equal numbers and will automatically identify the largest value of the 3.
2. You can submit your code via my email address or write it on the space provided.
CRITERIA 1 5 6 8 10
ACCURACY The output is The output has The output has The output has The output has
totally incorrect. shown 4 – 5 shown 2 – 3 shown 1 error. no error/s.
errors. errors.
CODE EFFICIENCY Codes do not Codes generate Codes generate Codes generate Codes generate
work. output with 4 – output with 2 – output with 1 the output
5 errors. 3 errors. error. desired.
TIMELINESS Did not submit Exceeded a Submitted 3 – Submitted 1 – Submitted on
at all. week or more 5 days after the 2 days after or before the
after deadline. deadline. deadline. deadline.
TOTAL
4. The activity will be scored using the Rubrics below:
WRITE
Assess
Multiple Choice. Choose the letter of the best answer. Write the chosen letter
on a separate sheet of paper.
2. It checks if the value of left operand is greater than or equal to the value
of right operand, if yes then condition becomes true.
a. <
b. >
c. <=
d. >=
a. Arithmetic
b. Logical
c. Relational
d. Operator
4. It checks if the value of left operand is less than the value of right
operand, if yes then condition becomes true.
a. <
b. >
c. >=
d. <=
5. It is called Logical AND operator. If both the operands are non-zero, then
condition becomes true.
a. &&
b. ||
c. >=
d. !
Reflect
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
____________________________.
________________________________________________________________
________________________________________________________________