0% found this document useful (0 votes)
3 views11 pages

Module 1 Ste Computer Programming Arithmetic Operators

This self-learning module for Grade 10 Computer Programming focuses on Arithmetic, Logical, and Relational Operators, providing definitions, applications, and examples in programming languages like C, JavaScript, and Java. It includes activities, a problem-solving drill, and emphasizes the importance of operators in programming for decision-making and calculations. The module is designed for home-based learning and encourages students to consult teachers for assistance.

Uploaded by

zgonrejas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views11 pages

Module 1 Ste Computer Programming Arithmetic Operators

This self-learning module for Grade 10 Computer Programming focuses on Arithmetic, Logical, and Relational Operators, providing definitions, applications, and examples in programming languages like C, JavaScript, and Java. It includes activities, a problem-solving drill, and emphasizes the importance of operators in programming for decision-making and calculations. The module is designed for home-based learning and encourages students to consult teachers for assistance.

Uploaded by

zgonrejas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

10

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.

Published by the Department of Education – Regional Office VIII


Regional Director: Ma. Gemma Mercado Ledesma
Assistant Regional Director: Bebiano Inhog Sentillas

Development Team of the Module


Writers: Michael Steve B. Acuin and Jocelyn L. Sayson
Language Editors: Bernie Jude R. Lamograr
Content Editors: Brian Jojit B. Kitane
Management Team:
Rosemarie M. Guino EdD, OIC – Chief, CLMD
Ryan R. Tiu EdD, EPS, CLMD – Science
Joy B. Bihag, EPS, CLMD – LRMS
Mark Chester Anthony G. Tamayo, Chief, CID
Arnulfo Q. Banzon, EPS, CID – Science
Gretel Laura Moscare-Cadiong, EPS, CID - LRMS

Printed in the Philippines by ________________________

Department of Education – Regional Office VIII

Office Address: Government Center, Candahug, Palo, Leyte

Telefax: 053 - 3233156


E-mail Address: [email protected].
Introductory Message
This Self-Learning Module (SLM) is prepared so that you, our dear learners,
can 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 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

Most Essential Learning Competency


Illustrate the use of Arithmetic, Logical and Relational Operators.

After going through this self-learning module, you are expected to:

1. Identify the different Arithmetic, Logical and Relational Operators.


2. Define the different Arithmetic, Logical and Relational Operators.
3. Apply Arithmetic, Logical and Relational Operators on a computer
program.

In programming, an operator is a special symbol that tells the


computer to perform mathematical, relational or logical operation to
produce a desired 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.

The figure below illustrates the role of an operator in a computer


program. 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 of variables that are fed into it.

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

In your previous lesson, we learned how to design a flowchart of a


simple program.

A flowchart is a visual outline of an algorithm in which the steps and


processes to be followed are represented by symbols. There are actually two
kinds of flowcharts: the system flowcharts and the program flowchart
A system flowchart is a diagrammatic representation of the broad flow
of work, documents and operations.
A program flowchart, on the other hand, is a diagrammatic
representation of a solution to a given problem for which the program is
written.
Now, we will learn what are the different types of operators in
computer programming which plays a big role in doing decision making skills
that affects the flow of the entire application.

Drill: Wolf, Goat, Cabbage problem


Once upon a time a farmer went to a market and purchased a wolf,
a goat, and a cabbage. On his way home, the farmer came to the bank of
a river and rented a boat. But crossing the river by boat, the farmer could
carry only himself and a single one of his purchases: the wolf, the goat, or
the cabbage.
If left unattended together, the wolf would eat the goat, or the goat
would eat the cabbage.
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 make a simple program that can help the farmer?

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.

Item Value Legend:


start
Cabbage = 1
Goat = 2
Wolf = 3
Which items will you
leave behind?

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”

“Item1 will eat


Item2”

stop
Arithmetic Operators

Computer programs are widely used for mathematical calculations.


We 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 concepts exist in Computer Programming.

Take a look at the following two examples


1. 2 + 3
2. P(x) = x4 + 7x3 - 5x + 9.

These two statements are called arithmetic expressions in a


programming 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.

Similarly, a programming language provides various arithmetic


operators. The following table lists down a few of the important arithmetic
operators available in C programming language. Assume variable A holds
10 and variable B holds 20, then

Operator Description Example


s

+ Adds two operands A+B will give 30

- Subtracts second operand from the first A–B will give -10

* Multiplies both operands A*B will give 200

/ Divides numerator by de-numerator B/A will give 2

% This gives remainder of an integer division B%A will give 0


Simple example in Javascript Programming

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.

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. Assume variable A holds 1 and variable B holds 0, then

Operator Description Example


s

&& Called Logical AND operator. If both the (A && B) is false


operands are non-zero, then condition
becomes true.

|| Called Logical OR Operator. If any of the two (A || B) is true.


operands is non-zero, then condition
becomes true.
! Called Logical NOT Operator. Use to reverses !(A && B) is true.
the logical state of its operand. If a condition
is true then Logical NOT operator will make
false.

Simple example in Javascript Programming

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

Here, it is obvious that variable A is greater than B in value. 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 mean 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,

Relation Meaning Example


al
Operator
s

> 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 (A < B) is 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.

<= Checks if the value of left operand is less (A <= B) is true.


than or equal to the value of right operand,
if yes then condition becomes true.

== Checks if the values of two operands are (A == B) is not true.


equal or not, if yes then condition becomes
true.

!= Checks if the values of two operands are (A != B) is true


equal or not, if values are not equal then
condition becomes true.

Simple example in Javascript Programming

function myFunction() {

var age, voteable;

age = document.getElementById("age").value;

voteable = (age < 18) ? "Too young":"Old enough";

document.getElementById("demo").innerHTML = voteable + " to vote.";

}
References
“Wolf and Cabbage Problem”, Wikipedia, Accessed January 23, 2021
https://en.wikipedia.org/wiki/Wolf,_goat_and_cabbage_problem

Davidson Institute of Science Education. Wolf, Goat, Cabbage and Farmer


[Photograph]., Weizmann Institute of Science.
https://www.futurelearn.com/info/courses/recreational-math/0/steps/43518

“Relational and Logical Operators”, Accessed Feb 1, 2021


https://www.tutorialspoint.com/relational-and-logical-operators-in-c

“Conditional Statements Exercises”, Accessed Feb 5, 2021


https://www.w3resource.com/c-programming-exercises/conditional-statement/
index.php

For inquiries or feedback, please write or call:

Department of Education – Regional Office VIII – Curriculum and Learning


Management Division (CLMD) - Learning Resources Management Section (LRMS)

Government Center, Candahug, Palo, Leyte, 6501

Telefax: (053) 323-3156; 323-3854; 824-4627

Email Address: *[email protected]


*[email protected] *[email protected]

You might also like