[go: up one dir, main page]

0% found this document useful (0 votes)
1 views6 pages

Algorithm Exercises

The document outlines a series of algorithm exercises in pseudocode format, covering a wide range of programming concepts such as conditional statements, loops, and data handling. Each exercise requires the development of algorithms to perform specific tasks, such as determining even or odd numbers, calculating ideal weight based on height and gender, and processing student grades. The exercises are designed to enhance understanding of algorithmic thinking and problem-solving skills in programming.
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)
1 views6 pages

Algorithm Exercises

The document outlines a series of algorithm exercises in pseudocode format, covering a wide range of programming concepts such as conditional statements, loops, and data handling. Each exercise requires the development of algorithms to perform specific tasks, such as determining even or odd numbers, calculating ideal weight based on height and gender, and processing student grades. The exercises are designed to enhance understanding of algorithmic thinking and problem-solving skills in programming.
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/ 6

Algorithm exercises

1. Develop an algorithm in pseudocode that performs the reading of a


integer number and present a message informing whether the number is even or
odd.
Even or Odd algorithm
var
n: integer
start
write("Enter an integer: ")
she reads
if (n mod 2 = 0) then
write("The number: ",n," is even")
senao
write("The number: ",n," is odd")
fimse
final algorithm

2. Develop an algorithm in pseudocode that performs the reading of a value.


that is between the range of 1 to 9. After reading the value provided by the user,
the value is within range
allowed”, if the user provides the value within this range, or the message “The value
is out of the allowed range," if the user provides values less than 1 or
greater than 9.

3. Develop a pseudocode algorithm that reads the name and


the sex of a person, outputting one of the following
"Dear Sir," for gender specified as male, or the message
"Mrs.", for the sex indicated as female. Present in the sequence of
message printed the person's name.

4. Develop an algorithm in pseudocode that reads a number. If positive


store it ina variable called "A", if it is negative, into a variable
call "B". At the end, show the result of the two variables.

5. Using the height and gender of a person as input data, build


an algorithm in pseudocode that calculates ideal weight, using the following
Formulas: For men: (72.7*h)– 58 For women: (62.1*h)– 44.7 Where h
equivalent to the person's height

6. Create a pseudocode algorithm to read four values related to


four school grades of a student and print a message saying that the
a student was approved if the value of the school average is greater than or equal to 5. If the student
It was not approved, indicate a message informing this condition. Present.
along with one of the messages the student's average value for any
condition.

7. Create an algorithm in pseudocode to read four values related to


four school grades of a student and print a message saying that the
The student was approved if the value of the school average is greater than or equal to 7.0. If the
If the average value is less than 7.0, request the exam score, add it to the value.
from the average and obtain a new average. If the new average is greater than or equal to 5, present it.
A message saying that the student has passed the exam. If the student has not.
approved, indicate a message informing of this condition. Present together.
with the messages the student's average value, under any condition.

8. Create an algorithm in pseudocode to read the year of birth of


a person, calculate and show their age and also check and show if they
is already of voting age (16 years or older) and to obtain the driver's license
License (18 years or older).

9. Create an algorithm in pseudocode to read the code of a certain


product and show its classification. Use the following table as a reference:

10. Write an algorithm to read three integer values and display them on the screen.
the largest and the smallest of them. Consider that all the values are different.

11. Write an algorithm to read five integer values, calculate their


average, and print on the screen the numbers that are above the average.

12. Write an algorithm to read the number of class hours of two


teachers and the amount per hour received by each one. Show on the screen which of the
Teachers have a higher total salary.

13. Write an algorithm that reads three values for the sides of a triangle.
The algorithm must check if the triangle is equilateral (all sides equal),
isosceles (two equal sides) or scalene (all sides different).

14. Write an algorithm that reads integer values into two variables.
different.
If the rest of theif the division of the first by the second is 1, show the sum of these.
variables plus the remainder of the division;
If it is 2, write whether the first and second values are even or odd;
If it is equal to 3, multiply the sum of the read values by the first one.
If it is equal to 4divide the sum of the read numbers by the second, if this is
different from zero.
In any other situation, show the square of the numbers read.

15. Write an algorithm to read two values and one of the following
operations to be performed (coded as follows: 1– Addition, 2–
Subtraction, 3– Multiplication and 4–Division). Calculate and write the result of this
operation on the two read values.

16. Write an algorithm that reads an integer. If the number read is


positive, write a message indicating whether it is even or odd. If the number
This number is not positive.

17. Zezinho bought a microcomputer to control daily performance.


from his work as a fisherman. Every time he brings a heavier catch of fish
what is established by the fishing regulation of the state of Santa Catarina (50
kilograms) must pay a fine of R$ 4.00 for each excess kilogram. Zezinho needs that
You create an algorithm that reads the weight of fish and checks if there is an excess. If
There will be, the excess and the amount of the fine that Zezinho will have to pay. Otherwise
show a message that he should not pay anything.

18. Create an algorithm that receives a person's salary amount and the amount
of the intended financing. If the financing is less than or equal to 5
the salary of the person, the algorithm should write 'Financing'
Granted; otherwise, he must write 'Funding Denied'. Independent
whether to grant the financing or not, the algorithm will later write the sentence.
Thank you for consulting us.

19. The Environment Secretary, which controls the pollution index, maintains
3 groups of industries that are highly polluting to the environment. The index
the acceptable pollution varies from 0 (zero) to 0.25. If the index rises to 0.3 the
industries of the 1st group are summoned to suspend their activities, if the index
to grow to 0.4, the industries of the 1st and 2nd group are urged to suspend.
their activities, if the index reaches 0.5 all groups must be notified to
paralyze their activities. Create an algorithm that reads the pollution index
issue the appropriate notification to the different groups of companies.

20. Make a program that reads 4 values X, A, B, and C where X is a number.


integer and positive and A, B, and C are any real values. The program must
write the read values and:
If X = 1, write the three values A, B, and C in ascending order.
If X = 2, thenreverse the three values A, B, and C in descending order;
If X = 3, write the three values A, B, and C so that the greatest value remains.
among the other two;
If X is not one of the three values above, give a message indicating that.

21. Develop an algorithm that informs whether a given year is a leap year or not. Note:
A year is a leap year if it is divisible by 400 or if it is divisible by 4 and not
by 100.

22. Create an algorithm that determines the largest among N numbers. The condition
The stop is to input a value 0, that is, the algorithm should process the largest.
until the input is equal to 0 (ZERO).

23. Create an algorithm that counts from 1 to 100 and emits at each multiple of 10.
Multiple of 10.

24. Develop an algorithm that generates and writes the odd numbers between
numbers between 100 and 200.

25. Build an algorithm that reads 50 positive integer values and:


Find the highest value
Find the smallest value
Calculate the average of the read numbers
26. Create an algorithm that:
• Read an indefinite number of lines, each containing the age ofUm
individual.
Calculate and write the average age of this group of individuals.

27. There is a dataset containing height and gender (male,


(female) of 50 people. Create an algorithm that calculates and writes:
The tallest and the shortest height of the group;
The averageof women's height;
The number of men.

28. The conversion from degrees Fahrenheit to degrees Celsius is obtained by: C ←
(F-32)*5/9. Create an algorithm that calculates and writes a table in Celsius
in function of Fahrenheit degrees, which range from 50 to 150 in increments of 2.

29. A merchant wants to assess the profit from the goods.


that he sells. For this, he sent to type each merchandise with the name,
purchase price selling price of goods. Create an algorithm that:
Determine and write how many mgoods provide:
Lower profit 10%;
Profit between 10% and 20%;
Profit greater than 20%.
• Determine and write the total purchase and sale value of all the
goods, as well as the total profit.

30. Assuming that the population of country A is around 90,000,000.


inhabitants with an annual growth rate of 3% and that the population of a
country B has approximately 200,000,000 inhabitants with an annual rate of
growth of 1.5%. Create an algorithm that calculates and writes the number of
years needed for the population of country A to exceed or equal that of
population of country B, keeping these growth rates.

31. Redo exercise 77 by reading the rates and the populations.

32. A certain radioactive material loses half of its mass every


50 seconds. Given the initial mass, in grams, create a program that
determine the time needed for this mass to become less than 0.5
initial mass
minutes and seconds.

33. A survey is desired regarding the absence of students at


first Programming Logic test for each of the 10 classes
existing. For each class, a set of values is provided, with
the first two values of the set correspond to the identification of the class (A, B,
C...) and the number of enrolled students. The other values in this set
contain the student's registration number and the letter A or P in case the student
be absent or present, respectively. Create a program that:
For each class, calculate the percentagein absence and write the identification
of the class and the calculated percentage.
Determine and write how many classes had a percentage of absence.
greater than 5%.

34. A certain company conducted a survey to find out if people liked it.
or not of a new product launched in the market. For this, the gender was provided.
of the interviewee and their response (yes or no). Knowing that there were
interviewed 2,000 people, create an algorithm that calculates and writes:
The number of people who answered yes;
The number of people thatThey answered no;
The percentage of female respondents who answered yes;
The percentage of male respondents who answered no;

35. A survey of TV channel audience was conducted in several houses of


a certain city, on a specific day. For each house visited, the
número do canal (4, 5, 7, 12) e o número de pessoas que o estavam assistindo
in that house. If the television was turned off, nothing was noted, that is,
this house did not enter the search. Create an algorithm that:
Read the number of houses surveyed;
Calculate the audience percentage for each broadcaster;
Write the number of each channel and its respective percentage.

36. A university wants to conduct a survey regarding its


entrance exam. For each course, the following set of values is provided:
A course code.
Number of vacancies;
Number of male candidates;
Number of female candidates.
Create a program that:
Calculate and write, for each course, the number ofcandidates per vacancy and the
percentage of female candidates (also write the code
correspondent of the course);
Determine the highest number of candidates per position and write down that number.
together with the corresponding course code (assuming there is no tie);
Calculate and write the total number of candidates.

37. The evaluation system of a certain subject follows the


following criteria:
During the semester, three grades are given;
The final grade is obtained by the arithmetic average of the grades given duringthe course
A student is considered approved if they have a final grade equal to or greater than 6.0 and
who has attended at least 75% of the classes. Create an algorithm that:
1. read a dataset containing the enrollment number, the three grades and the
attendance (number of classes attended) for 100 students.
2. Calculate:
The final grade of each student;
The highest and lowest grade of the class;
The average grade of the class;
The total number of failed students;
The percentage of students failed due to insufficient attendance.
3. Write
For each student, the registration number, attendance, final grade and thecode
(approved or disapproved)
• All values that were calculated in item 2;

You might also like