Anda di halaman 1dari 5

EXERCISE NO.

2
Name: Andrew A. Juarez

Date: 05 July 2016

Year & Section: PBDIT 4013

Score:__________________

1. What are the elements of Algorithm? What are the types of


constants?
-

The element of Algorithm are Constant, Variable and

Expression.

The types of Constant are Numerical, Character and

String.
2. What are the operators used in relational expressions?
-

less than (<), less than or equal to (<=), greater than

(>), greater than or equal to (>=), equal to (==) and not equal
to (/=).
3. How the arithmetic expression is evaluated?
-

when evaluating a relational expression, the value to

of he left operand is compared to the value to the right operand


to determine whether the entire expression is true or false.
-

if the operand is a variable then its corresponding

value will be used for comparison.


-

if the operand is a numeric or string expression, said

expression is evaluated first to determine its final value that


will used for comparison.
-

if a portion of numeric or string expression is

variable, then its corresponding value will be used to arrive at


the final value of the said expression.
-

when comparing string values, each character or both

operands are compared according to its ASCII code equivalent.


The comparison is made from left to right one character at a time
using the value of the ASCII code as the basis of comparison.
one operand is shorter that the other, the shorter operand is
padded with spaces to make the length of both operands equal.

If

4. What are the Boolean Expressions?


-

is either a relational or logical expression that is

either True or False.

Boolean expression can compare data of any

type as long as both parts of the expression have the same basic
data type.
5. How the Logical Expressions are evaluated?
-

when evaluating complex logical expression, the

precedence rule of logical expression or the hierarchy of logical


expression evaluation must be taken into consideration to
determine the order by which the operations are to be evaluated.
According to the precedence rule, operators with a higher
hierarchy or priority are evaluated first.
6. How to write a good algorithm?
-

Inputs and outputs should be defined precisely.

steps in algorithm should be clear and unambiguous.

Each

Algorithm

should be most effective among many different ways to solve a


problem.

An algorithm shouldnt have computer code.

Instead,

the algorithm should be written in such a way that it can be used


in similar programming languages.
A. Determine and write V if the variable is Valid and INV if
invalid.
_____V_______1. COM
_____V_______2. HO_ME
____INV______3. SIS-TER
____INV______4. _BABY
____INV______5. XYZ_
_____V_______6. DATA
_____V_______7. RAW
_____V_______8. DATA1
____INV______9. NA_ _ME
_____V_______10. NONE

B. Write the correct letter of the correct answer.


__a___1.) 2+2=5 is what type of expression ?
a. Arithmetic

b. Boolean

c. String

__b___2.) 2<3 is what type of expression?


a. Arithmetic

b. Boolean

c. String

__c___3.) Good is merciful and compassionate is an example of


a. Arithmetic

b. Boolean

c. String

_2*3__4.) In the Expression 2*3+4-2, which will be the first


priority?
a. 2*2

b. 3+4

c.4-2

__c___5.) In the Expression (3*3)+4/2%2, which will be the last


priority?
a.(3*3)

b.34%2

c.9+4

__c___6.) 1 is what type of Constant?


a. Character

b. real numeric

c. Integer

__b___7.) DATA<data will yield a Boolean value of


a. True

b. False

c. None

__b___8.)5/1 will obtain the value of


a. 5.0

b. 5

c. five

__a___9.)5*25 will obtain a value of


a. 125

b. 125.0

c. 125.00

__a___10.) 10*5+2 is an algorithm statement.


a. True

b. False

C. Exercises

None

Let:

A = 5

B = 1.0

C=3

1.) D = (A+B) * C
D = (5 + 1.0) * 3
D = 6.0 * 3
D = 18.0
2.) D = (A + B) * C/2 % 1
D = (5 + 1.0) * 3/2 % 1
D = 6.0 * 1
D = 6.0
3.) D = B * C + 3 / 2 A
D
D
D
D

=
=
=
=

1.0 * 3 + 3/2 A
3.0 + 1.5 5
4.5 5
-0.5
4.) D = B * 2 + 3 * A (A%2)

D
D
D
D

=
=
=
=

1.0 * 2 + 3 * 5 5%2
2.0 + 15 2
17.0 2
15.0
5.) A < B

5 < 1.0
FALSE

6.) (A + B < C)
5 + 1.0 < 3
6 < 3
FALSE
7.) D = (A * B) + C / ( 4 + 3)
D = (5 * 1.0) + 3 / (4 + 3)
D = 9 / 7
D = 1.29

D=C

8.) D = (A < B) AND (C < B)


D = (5 < 1.0) AND (3 < 1)
D = FALSE AND FALSE
D = FALSE
9.) D = NOT (A < B) AND (C < B)
D = NOT (5 < 1.0) AND (3 < 1.0)
D = NOT FALSE AND FALSE
D = FALSE
10.) D = (NOT (A < B) OR NOT (C = B)
D = (NOT (5 < 1.0) OR NOT (3 = 1.0)
D = NOT (FALSE) OR NOT FALSE
D = FALSE

Anda mungkin juga menyukai