0% found this document useful (0 votes)
18K views10 pages

ITE6102 LaboratoryExercise005

The document describes 3 programming problems involving conditionals. The first 2 problems involve accepting an integer input and displaying different output strings based on the input using IF statements or a SWITCH statement. The third problem involves dividing two floating point numbers entered by the user and handling scenarios like division by zero. The pseudocode provided shows how to declare variables, get input, and use conditionals like IF, ELSE IF, SWITCH, and CASE to selectively execute code based on the input values.

Uploaded by

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

ITE6102 LaboratoryExercise005

The document describes 3 programming problems involving conditionals. The first 2 problems involve accepting an integer input and displaying different output strings based on the input using IF statements or a SWITCH statement. The third problem involves dividing two floating point numbers entered by the user and handling scenarios like division by zero. The pseudocode provided shows how to declare variables, get input, and use conditionals like IF, ELSE IF, SWITCH, and CASE to selectively execute code based on the input values.

Uploaded by

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

Questions:

1. Write a program that will accept an integer and execute one of the following based on the
input using IF statements:
a. If 0, display only “Hello World”.
b. If 1, display only “I am Groot”.
c. If 2, display only “To the Top”.
d. If 3, display only “Where is the horizon”.
e. If 4, display only “I do not know”.
f. If none of the above, display only “Yeah, I will.”
START

Declare a

Accept a

false true
a=0

false true Display “Hello World”


a=1

false true Display “I am Groot”


a=2

false true Display “To the top”


a=3

Display “Where is the horizon”

false true
a=4

Display “Yeah, I will.” Display “I do not know”

END
Pseudocode:
1. Declare a
2. Input a
3. IF a=0 then
Output “Hello World”
Else IF a=1 then
Output “I am Groot”
Else IF a=2 then
Output “To the top”
Else IF a=3 then
Output “Where is the horizon
Else IF a=4 then
Output “I do now know”
Else
Output “Yeah, I will”.
End
4. End
2. Write a program that will accept an integer and execute one of the following based on the
input using SWITCH statements:
a. If 0, display only “Hello World”.
b. If 1, display only “I am good”.
c. If 2, display only “To the Top”.
d. If 3, display only “Where is the horizon”.
e. If 4, display only “I do not know”.
f. If none of the above, display only “Yeah, I will.”
START

Declare a

Accept a

Switch a

true
Case
Display “Hello World”
0

false

Case true Display “I am good”


1

false

Case true
Display “To the top”
2

false

Case true Display “Where is the


3 horizon”

false

true Display “I do not


Case
4 know”

false

Display “Yeah, I will.”

END
Pseudocode:
1. Declare a
2. Input a
3. Switch a
4. Case 0 then
Output “Hello World”
Break
5. Case 1 then
Output “I am good”
Break
6. Case 2 then
Output “To the top”
Break
7. Case 3 then
Output “Where is the horizon”
Break
8. Case 4 then
Output “I do not know”
Break
9. Default
Output “Yeah, I will.”
10. End
3. Write a program that will divide the two floating points entered by the user (first number
entered divided by the second number entered). Make sure your application handles all
possible scenarios with floating points.
START

Declare x,y

Accept x

Accept y

false true
y=0

Display “The quotient of


the two number is” + x/y
false true
+ “.” x=0

Display “Any number


Display “0/0 is
divided by zero is
undefined, its limit is
undefined. Its limit can
indeterminate in form”.
be positive or negative
infinity”.

End
Pseudocode:
1. Declare x,y
2. Input x
3. Input y
4. If y = 0 then
If x = 0 then
Output “0/0 is undefined, its limit is indeterminate in form”.
Else
Output “Any number divided by zero is undefined. Its limit can be positive or negative infinity”.

End
Else
Output “The quotient of the two number is” + x/y + “.”

End

5. End
4. What can you conclude from this activity?

Therefore I conclude that in this activity, the two conditionals IFs and SWITCHEs are
useful when doing coding as it makes the code systematic especially if I’ll encounter
problems with different statements.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy