0% found this document useful (0 votes)
6 views37 pages

Conditional Structures Algorithms Guide

The document contains a series of exercises focused on conditional structures and algorithm design, primarily for educational purposes at the National University of Trujillo. Each exercise presents a specific problem, such as determining the greater of two numbers, checking if a number is even or odd, and solving quadratic equations, along with pseudocode and flowchart representations. The exercises aim to strengthen programming fundamentals through practical applications and algorithmic thinking.

Translated by

ScribdTranslations
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)
6 views37 pages

Conditional Structures Algorithms Guide

The document contains a series of exercises focused on conditional structures and algorithm design, primarily for educational purposes at the National University of Trujillo. Each exercise presents a specific problem, such as determining the greater of two numbers, checking if a number is even or odd, and solving quadratic equations, along with pseudocode and flowchart representations. The exercises aim to strengthen programming fundamentals through practical applications and algorithmic thinking.

Translated by

ScribdTranslations
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

National University of Trujillo

EXERCISES ON CONDITIONAL STRUCTURES


TO DO:
ALGORITHM (PSEUDOCODE AND FLOWCHART).

1. Write an algorithm that allows the input of 02 numbers and determines which is the greater.
which is the smallest of them.

Start

A,B

YES NO
A>B

A is greater B is greater

End
National University of Trujillo

2. A number is to be entered from the keyboard to determine if it is even or odd.

Start

YES NO
a/2 is in Z

it is for a is odd

End
National University of Trujillo

3. Create an algorithm that allows entering a real number and reports its absolute value.

Start

|A|

YES NO
A>0

A
-A

End
National University of Trujillo

4. Write an algorithm to solve a quadratic equation of the form:


Ax² + Bx + C = 0

Start

A, B, C, X1, X2

A*X**2+B*X+C=0

YES NO
A>0

X1 = [-B + (B^2 - 4*A*C)^0.5] / (2*A)


X2=[-B-(B**2-4*A*C)**0.2]/(2*A) X1=X2=-C/B

End
National University of Trujillo

5. Write an algorithm that simulates a calculator with four basic operations (addition +, subtraction -
-, multiplication * and division /”. The user will enter a number, the operator, and the second
number and the result will be displayed next.

Start

A, B, S, R, M, D

YES NO
B≠0

S=A+B S=A
R=A-B R=A
M=A*B M=0
D=A/B D=ERROR

End
National University of Trujillo

6. A store has put on sale the wholesale of a certain product, offering a


15% discount for the purchase of more than 3 dozen and 10% otherwise. Also for
When purchasing more than 3 dozen, one unit of the product is given as a gift for each dozen.
excess over 3. Design an algorithm that determines the amount of the purchase, the amount of the
discount, the amount to pay and the number of gift units for the purchase of a certain
number of dozens of the product.

Start

Dozens, price

Monto Comp =
dozens*Price

YES NO
Dozens
>3

Monto Descuento = 0.15* Mont Desc. =0.10*Mc


Mc Obs= 0
Obsequio= #docenas -3

Amount paid = M purchase - M discount.

M comp, M desc, M
gift, offering

Final

Monto Descuento = 0.15*


Mc
Gift = #dozens -3
National University of Trujillo

7. Consider a quadratic expression such as: x² - x - 6


To describe where this expression is positive (i.e., greater than zero), it must be described
a set of numbers that are less than the smallest root (which is -2), or,
greater than the largest root (which is +3). Write an algorithm that displays the message
"Positive" when this formula has positive values.

Start

F,X

F=X**2-X-6

YES NO
-2 < X < 3

F is positive F is not
positive

End
National University of Trujillo

8. Consider a quadratic expression such as: x² - 4x + 3


To describe where this expression is negative, one must describe a set of numbers.
that are simultaneously greater than the smallest root (+1) and less than the largest root
big (+3). Write an algorithm that displays the message 'Negative' when it is
the formula has negative values.

Start

F,X

F=X**2-4X-3

YES NO
1<X<3

F is negative F is not
negative

End
National University of Trujillo

9. Write an algorithm that displays the ALERT message if the value of the variable
temperature is greater than or equal to 150, or if the value of the pressure variable is less than or
equal to 300, or both. Otherwise, it should display the message NORMAL.

Start

T,P

YES NO
T>=150 or
P<=300

ALERT
NORMAL

End
National University of Trujillo

10. Students of ALGORITHMS will only pass if the partial exam grade is higher
or equal to 10.5 and if the number of solved programs is at least 15. Create an algorithm
that determines whether a student is passed or failed.

Start

E.P, N

YES NO
P≥10.5

NO
N≥15

YES

APPROVE DISAPPROVE

Final
National University of Trujillo

11. Write an algorithm that allows the input of 03 numbers and determines which is the largest.
which is the smallest of them.

Start

a, b, c

YES NO
a is greater than b

NO
b>c YES
c >a

YES NO
NO YES NO
a>c c>b

a is greater c is greater b is greater

Final
National University of Trujillo

12. Calculate and visualize the sum and product of two even numbers (entered via keyboard)
ranging from 30 to 300, both inclusive. Show the out of range message if the
numbers are not between 30 and 300.

Start

a, b, s, p

YES NO
a is greater than b

S=a+b
P=a*b

S, P Out of range

Final
National University of Trujillo

13. Create an algorithm that allows me to enter the value of 3 angles in sexagesimal degrees, and
report if they are the angles of a triangle, and also indicate if it is a right triangle,
obtuse angle or acute angle.

Start

A,B,C

A+B+C=180°

YES A=90° or NO
B=90° or
C=90°

It is a rectangle YES 90°<A<180° NO


o
90° < A < 180°
o
90° < A < 180°

It is obtuse-angled It is an acute angle

End
National University of Trujillo

14. Enter two numbers via keyboard (a, b) and perform the following operations as applicable:
a. Add the numbers if they are even.
b. Subtract a-b, if they are odd.
c. Multiply a*b, if one is even and the other is odd.

Start

A,B

YES NO
A is even,
B is even

A+B YES NO
It is
odd
B is even

A*B A-B

End
National University of Trujillo

15. Determine the price to be paid for the purchase of a quantity of the same shirts.
For example, if the price of size S shirts is $85, size M is $95, and size L is $
100. The quantity of shirts to buy and the size must be entered.

Start

X, S, M, L

S M L

85*X 95*X 100*X

End
National University of Trujillo

WORKSHOP ON STRENGTHENING PROGRAMMING FUNDAMENTALS

1. Design an algorithm that reads the current time of day HH:MM:SS and determines how many hours, minutes and
seconds left to start a new day.

Start

READ (A:B:C), TF

TF=(23-A):(59-B):(60-C)

WRITE (TF)

End

[Link] that an individual wants to invest their capital in a bank and wants to know how much money they will earn.
after a month if the bank pays at a rate of 2% per month.
National University of Trujillo

Start

READ (G, C)

G=1.02C

WRITE (G)

End

A student wants to know what their final grade will be in the Algorithms subject. This grade
is composed of the following percentages:
55% of the average of their three partial grades.
30% of the final exam grade.
15% of the grading of a final project.
National University of Trujillo

Start

READ (C1, C2, C3,


PT, EF, TF

C1=0.55*PT
C2=0.3*EF
C3=0.15*TF
CT= C1+ C2 + C3

WRITE (CT)

End

4. Create an algorithm that calculates a person's age.

START

M, m, A, a, E

M>m
E=A-a E=A-a-1
National University of Trujillo

In English-speaking countries, it is common to give a person's height as the sum of a number.


whole feet plus an integer number of inches. Thus, a person's height could be 3' 2"
(3 feet 2 inches). Design an algorithm that determines a person's height in meters.
knowing your height in the English format. Consider that: 1 foot = 12 inches, 1 inch = 2.54 cm, 1 m =
100 cm.

Start
National University of Trujillo

READ (X, Y)

A = ((X * 12 + Y) * 2.54) / 100

TO WRITE (A)

End

A man wants to know how much money is generated from interest on the amount he has.
in investment in the bank. He will decide to reinvest the interest as long as it exceeds $7000,
and in that case, you want to know how much money you will finally have in your account.

Start

C, r, t

I = C * r * t / 100
Universidad Nacional de Trujillo

NO
I>7000

YES

I=I*r*t/100

Final

7. Determine if a student passes or fails a course, knowing that they will pass if their average of three
grades are greater than or equal to 70; fail otherwise.

Start

n32,n1,P

P=(n1+n2+n3)/3
National University of Trujillo

YES NO
P>=70

APPROVE
DISAPPROVES

End

In a store, a 20% discount is given to customers whose purchase exceeds $1000. What will it be?
the amount that a person will pay for their purchase?

Start

P1, P2, C

YES NO
C>1000
National University of Trujillo

P2=C
P1=0.80*C

P1 P2

Final

9. A worker needs to calculate his weekly salary, which is obtained in the following way:
If you work 40 hours or less, you are paid S/.16 per hour.
If you work more than 40 hours, you are paid S/.16 for each of the first 40 hours and S/.20 for each
overtime.

Start

S1, S2, #h

YES NO
#h<=40
National University of Trujillo

S1=16*#h S2 = 16 * #h + 20 * (#h - 40)

S1 S2

Final

10. Read two numbers and print them in ascending order.

Start

READ (A, B)

A> B

WRITE (B, A)
National University of Trujillo

End

11. A sick person weighing 70 kg is at rest and wants to know how many calories
consume your body throughout the time you perform the same activity. The activities that
You have been allowed to do only sleep or sit at rest. The data you have is
that while sleeping it consumes 1.08 calories per minute and while sitting at rest it consumes 1.66
calories per minute.

Start

READ (C1, C2, m1,


m2)

C1=1.08 * m1
C2=1.66 * m2

WRITE (C1, C2)

End
National University of Trujillo

12. Create an algorithm that prints the name of an item, key, original price, and its price with
discount. The discount is based on the key, if the key is 01 the discount is 10% and if the
the key is 02 the discount is 20% (there are only two keys).

Start

READ (P1, PD1, P2,


PD2)

PD1=0.1*P1
PD2=0.2*P2

The original price of the item:


(...), with the key number (...)
it was (…), but it obtained a price
discount of (…)

End
National University of Trujillo

13. Create an algorithm that calculates the total to be paid for the purchase of shirts. If three are purchased.
If you buy shirts or more, a 20% discount applies to the total purchase, and if they are less than three.
shirts a 10% discount.

Start

READ(C, Desc,
PC

YES NO
C>=3

Descuento=
20% Discount =
10%

TP=PC*#C*Desc.

WRITE (TP)

Final

A company wants to make a purchase of several pieces of the same type from a factory
spare parts. The company, depending on the total amount of the purchase, will decide what to do to pay.
to the manufacturer.
National University of Trujillo

If the total amount of the purchase exceeds $500,000, the company will have the capacity to invest in its
own money 55% of the purchase amount, borrow from the bank 30% and will pay the rest
requesting a loan from the manufacturer.
If the total amount of the purchase does not exceed $500,000, the company will have the capacity to invest in its
Own money 70% and the remaining 30% will be paid by requesting credit from the manufacturer.
The manufacturer charges an interest rate of 20% on the amount paid on credit.

Start

READ (Cant. Inv,


credit, loan, C)

YES NO
$50000
0

[Link]=0.55*C [Link] = 0.7 * C


Credit=0.15*C Credit=0.3*C
Loan=0.3*C Prestamo=0

Int = credit * 0.2

WRITE (Int)

Final
15. Hacer un algoritmo que permita ingresarun número y se reporte si es positivo, negativo o cero.
Universidad Nacional de Trujillo

Start

YES NO
N >= 0

N is positive N is negative
to zero

End

16. Create an algorithm that allows entering a real number and reports its absolute value.

Start
National University of Trujillo

YES NO
A>0

A
-A

End

17. Create an algorithm that allows me to input the value of 3 angles in sexagesimal degrees, and
report if they are the angles of a triangle, it should also show if it is right, obtuse or
acute angle.

Start

A,B,C
National University of Trujillo

A+B+C=180°

YES A=90° or NO
B=90° or
C=90°

It is a rectangle YES 90°<A<180°, NO


o
90° < A < 180°
o
90°<A<180°

It is obtuse It is an acute angle

End

18. Determine the price that must be paid for the purchase of a quantity of shirts of the same type, if
The price of size S shirts is $85, size M is $95, and size L is $100. It should be
enter the quantity of shirts to buy and the size.

Start

X, S, M, L
National University of Trujillo

S M L

85*X 95*X 100*X

End

19. Create a program that calculates the mileage fee for a grocery delivery person by asking for the
kilometers by keyboard. Knowing that S/. 250 is paid if the kilometers traveled are less than or
equal to 150 and S/. 350 if the mileage is greater than 150.

Start

#km, C
National University of Trujillo

YES NO
#km<=15
0

C=250
C=350

End

20. Program to enter a year and report if it is a leap year or not. A year is a leap year if it is a multiple of 4.
but not of 100 or a multiple of 400.

Start

A mod
400=0
National University of Trujillo

YES NO

It is a leap year
YES
A mod 4 = 0
y
A mod≠100
NO

It is not a leap year

End

21. In a parking lot, they charge S/. 1.5 per hour or fraction. Design an algorithm that
determine how much a customer must pay for the parking of their vehicle, knowing the time
parking hours and minutes.
22. Design an algorithm that determines whether a number is a positive even number or not.

Start

T.H, [Link], P

YES NO
[Link]>0
National University of Trujillo

T.H = T.H + 1
P = T.H * 1.5 T.H = T.H
P = T.H * 1.5

End

22. Design an algorithm that reads a three-digit number and determines whether it is a palindrome or not. A number is
A palindrome is equal to the reverse of the number.

Start

READ (ABC)

IF NO
X=ABC=CB
A

X is a palindrome X is not
palindrome
National University of Trujillo

End

23. Enter an integer, and if it ends in 2, 5, or 8, report the square of the number, if this
If it ends in 4, 7, or 9, report the number multiplied by 5 and report the same number otherwise.

Start

IF NO
A=…2; or
A=...5; or
A=…8

A**2 YES A=...4; or NO


A=…7; or
A=...9

A*5 A
National University of Trujillo

End

You might also like