Algorithm Exercises for Mathematics Degree
Algorithm Exercises for Mathematics Degree
1. The real estate agency Imóbilis only sells rectangular plots of land. Create an algorithm to read the
dimensions of a land and then display the area of the land.
algorithm "LandCalculation"
var
b, h, Area :inteiro
start
Write("Enter the value of the length of the land")
Leia(b)
Write("Enter the value of the land width")
Leia
Area <- (b * h)
The total area of the land
final algorithm
2. Create an algorithm to calculate how many horseshoes are needed to equip all the
horses bought for a stud farm.
algorithm "HorseshoeCalculation"
var
numferraduras:inteiro
numcavalos: inteiro
totalferraduras : inteiro
start
Enter the quantity of horses purchased:
Read(numberofhorses)
State the number of horseshoes needed to equip a horse
Read(number of horseshoes)
totalferraduras <- (numcavalos * numferraduras)
3. The bakery Hotpão sells a certain quantity of French breads and a quantity of cookies.
every day. Each roll costs R$ 0.12 and the cornbread costs R$ 1.50. At the end of the day, the owner wants to know
how much was raised from the sale of breads and cakes (together), and how much should be saved in an account of
savings (10% of the total collected). You have been hired to do the calculations for the owner. With
Based on these facts, create an algorithm to read the quantities of bread and rolls, and then calculate.
the requested data.
algorithm 'Hotpao'
var
quant_paes, quant_broas :real
total_vendas :real
quant_poupanca:real
start
Write("Enter the quantity of Breads Sold:")
Read(bread_quantity)
Enter the quantity of cookies sold:
Read (quantity_goods)
total_vendas <- (quant_paes * quant_broas)
Write("The total amount of sales from the bakery was ", total_sales )
savings_amount <- (total_sales * 0.1)
final algorithm
4. Write an algorithm to read the name and age of a person, and display how many days of life.
she has. Always consider complete years, and that a year has 365 days. Ex: a person
At 19 years old, you have lived 6935 days; see an example output: MARIA, YOU HAVE ALREADY LIVED 6935
DAYS
algorithm 'LifeDays'
var
name:character
idade:inteiro
dias_vida: inteiro
anos:inteiro
start
anos:=365
Write("Specify the user's name:")
Leia(name)
Write("Enter the age of the User:")
Leia(age)
days_life <- (38 * years)
Write(name, "You have lived", days_lived)
final algorithm
5. A driver wants to put X reais of gasoline in their tank. Write an algorithm to read the
price of a liter of gasoline and the amount paid, and display how many liters he was able to fill in the
tank.
Supply Algorithm
var
X:real
preco_litro:real
valor_pago:real
quant_litros:real
start
Write(" Enter the price of the liter:")
Read(price_per_liter)
Write("Enter the amount paid:")
Read(amount_paid)
liters_quantity <- amount_paid / price_per_liter
Write(" The amount of liters refueled was:", quant_litros, "liters")
fimalgorithm
6. The buffet restaurant Bem-Bão charges R$12.00 for each kilo of meal. Write an algorithm
that reads the weight of the dish assembled by the customer (in kilograms) and prints the amount to pay. Assume that the
the scale already deducts the weight of the plate.
Good-Bao algorithm
var
valorq, peso, pesoprato, valortotal: real
beginning
final algorithm
7. Enter the day and month of a date and inform how many days have passed since the beginning of
Yes. Forget about the leap year issue and always consider that a month has 30 days.
8. Create an algorithm to read three grades of a student in a subject and print their average.
weighted (the grades have respective weights of 1, 2, and 3).
algorithm 'AverageGrades'
var
nota1, nota2, nota3:real
media:real
nome:caractere
start
Enter the name of the Student:
Leia (name)
Write('Enter the student's first grade:')
Read(note1)
Enter the student's second grade:
Read(note2)
Write("Enter the student's third grade:")
Read(note3)
average <- ((grade1 + grade2 + grade3) / 3)
The student's average: , name, is average
final algorithm
9. A t-shirt factory produces small, medium, and large sizes, each one being
sold respectively for 10, 12 and 15 reais. Build an algorithm where the user provides the
quantidade de camisetas pequenas, médias e grandes referentes a uma venda, e a máquina
report how much the collected amount will be.
algorithm "SellTShirts"
var
quant_P : inteiro
quant_M : inteiro
quant_G : integer
total_venda : real
preco_P :real
preco_M :real
preco_G :real
start
preco_P <- 10.00
preco_M <- 12.00
preco_G <- 15.00
Enter the quantity of size P t-shirts:
Read(quantity_P)
Write("Enter the quantity of size M t-shirts:")
Read(quantity_M)
Enter the quantity of size G t-shirts:
Read(quant_G)
total_venda <- (quant_P * preco_P) + (quant_M * preco_M)+(quant_G * preco_G)
Write("The total value of the t-shirt is: R$", total_sale)
finalgorithm
10. Build an algorithm to calculate the distance between two points on the Cartesian plane. Each
A point is an ordered pair (x,y).
11. A factory controls the working time without accidents by the number of days. Make a
algorithm to convert this time into years, months, and days. Assume that each month always has
30 days.
12. Create an algorithm to read an employee's salary and increase it by 15%. After the increase,
discount 8% of taxes. Print the initial salary, the salary with the increase, and the final salary.
algorithm 'SalaryOfficials'
var
nome:caractere
salario_inicial: real
adjustment:real
salario_reajustado:real
desconto:real
salario_final:real
start
Write("Enter the employee's name:")
Leia(name)
Write(" Enter the employee's salary ", name)
Initial Salary
Read(initial_salary)
adjustment <- initial_salary * (15/100)
adjusted_salary <- adjustment + initial_salary
Write (name, ", received a 15% raise equivalent to R$ ", adjustment, " leaving with a salary of: R$ ")
,adjusted_salary)
discount <- adjusted_salary * (8/100)
final_salary <- adjusted_salary - deduction
Your salary had a discount of 8% R$, discount, related to social security, leaving the amount of
R$ " , final_salary)
fimalgorithm
13. Read an integer (assume up to three digits) and print the output in the following format:
CENTENA = x
DEZENA = x
UNIT = x
22. Pedrinho has a piggy bank with many coins, and he wants to know how many reais he has managed to save.
Save. Create an algorithm to read the quantity of each type of coin and print the total value.
saved, in reais. Consider that there are coins of 1, 5, 10, 25, and 50 cents, and still
1 real coins. If there are no coins of a certain type, the respective quantity is zero.
On a sunny day, you want to measure the height of a building, but the tape measure is not sufficient.
long. Assuming it is possible to measure your shadow and that of the building on the ground, and that you remember
From your height, create an algorithm to read the necessary data and calculate the height of the building.
A barrel of soda is made with 8 parts of mineral water and 2 parts of passion fruit juice.
Create an algorithm to calculate how many liters of water and juice are needed to make X.
liters of soda (reported by the user).
25. Calculate the volume of a cylindrical water tank.
26. Create an algorithm that takes three numbers, calculates, and displays the multiplication of those numbers.
27. Create an algorithm that receives two numbers, calculates and shows the division of the first number
per second. It is known that the second number cannot be zero, so it is not necessary to be
worry about validations.
28. Create an algorithm that receives two grades, calculates and shows the weighted average of these grades.
considering weight 2 for the first grade and weight 3 for the second grade.
29. Create an algorithm that receives the price of a product, calculates and displays the new price.
knowing that this suffered a 10% discount.
30. An employee receives a fixed salary plus 4% commission on sales. Make a
algorithm that receives the fixed salary of an employee and the amount of their sales, calculates and shows the
commission and the final salary of the employee.
31. Create an algorithm that receives a person's weight, calculates and displays:
a) the new weight if the person gains 15% over the entered weight;
b) the new weight if the person loses 20% of the entered weight.
32. Create an algorithm that receives a person's weight in kilograms, calculates, and displays this weight.
in grams.
33. Create an algorithm that calculates and displays the area of a trapezoid. It is known that: A = (larger base +
(base minor) * height) / 2;
34. Create an algorithm that calculates and displays the area of a square.
It is known that: A = side * side;
35. Create an algorithm that calculates and displays the area of a rhombus. It is known that: A =
(major_diagonal * minor_diagonal) / 2;
36. Create an algorithm that receives the value of the minimum wage and the value of an employee's salary,
calculate and show the number of minimum wages that this employee earns.
37. Create an algorithm that calculates and shows the multiplication table of a number entered by the user.
38. Create an algorithm that receives a person's year of birth and the current year, calculates and
show
a) the age of this person in years;
b) the age of this person in months;
c) the age of this person in days;
d) the age of this person in weeks.
39. João received his salary of R$ 1200.00 and needs to pay two bills (C1=R$ 200.00 and
C2=R$120.00) that are overdue. Since the bills are overdue, João will have to pay a fine of
2% on each bill. Create an algorithm that calculates and shows how much of João's salary will remain.
40. Create an algorithm that receives the values of the legs of a triangle, calculates and shows the value of
hypotenuse.