Module 1 Ste Computer Programming Arithmetic Operators
Module 1 Ste Computer Programming Arithmetic Operators
Computer
Programming
Quarter III – Module 1:
Arithmetic, Logical and Relational
Operators
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.
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 honest in using these.
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 best help you on your home-based learning.
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 read the instructions carefully before performing each task.
If you have any questions in using this SLM or any difficulty in answering
the tasks in this module, do not hesitate to consult your teacher or facilitator.
Thank you.
Explore
After going through this self-learning module, you are expected to:
INPUT OUTPUT
OPERATOR
This module will explain the concept of operators and it will take
you through the important arithmetic, relational and logical operators
available in C, Javascript, Java, and Visual Basic.
Learn
Here is a program that the farmer can use to check which of his purchased item
can be left together on either side of the river.
Here’s a program flowchart that you can follow when you start coding later.
Enter Item1
Enter Item2
F F “Your Items
Item1 > Item2 (Item2 -1) =
are safe”
Item1
T
T
F
(Item1 -1) = “Your Items “Item2 will eat
Item2 are safe” Item1”
stop
Arithmetic Operators
- Subtracts second operand from the first A–B will give -10
var x = 5;
var y = 2;
var z = x - y;
console.log(z);
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, OR and
NOT 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
let x = 1;
if (x > 0) alert( 'Greater than zero!' );
let hour = 9;
if (hour < 10 || hour > 18) {
alert( 'The office is closed.' );
}
Relational Operators
Relational operators are important for making decisions. They allow
us to compare numeric and char (chars are treated like numbers in C++)
values to determine if one is greater than, less than, equal to, or not equal
to another.
Relational operators are binary, meaning they require two operands.
Relational operators have left to right associativity. Left to right
associativity means that when two operators of same precedence are
adjacent, the left most operator is evaluated first.
Consider a situation where we create two variables and assign them
some values as follows
A = 20
B = 10
> 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 greater (A >= B) is not true.
than or equal to the value of right operand,
if yes then condition becomes true.
function myFunction() {
age = document.getElementById("age").value;
}
References
“Wolf and Cabbage Problem”, Wikipedia, Accessed January 23, 2021
https://en.wikipedia.org/wiki/Wolf,_goat_and_cabbage_problem