Conditional Structures Algorithms Guide
Conditional Structures Algorithms Guide
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
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
Start
A, B, C, X1, X2
A*X**2+B*X+C=0
YES NO
A>0
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
Start
Dozens, price
Monto Comp =
dozens*Price
YES NO
Dozens
>3
M comp, M desc, M
gift, offering
Final
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
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
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°
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
End
National University of Trujillo
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
C1=0.55*PT
C2=0.3*EF
C3=0.15*TF
CT= C1+ C2 + C3
WRITE (CT)
End
START
M, m, A, a, E
M>m
E=A-a E=A-a-1
National University of Trujillo
Start
National University of Trujillo
READ (X, Y)
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 S2
Final
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
C1=1.08 * m1
C2=1.66 * m2
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
PD1=0.1*P1
PD2=0.2*P2
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
YES NO
$50000
0
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°
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
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
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*5 A
National University of Trujillo
End