0% found this document useful (0 votes)
15 views5 pages

Programming Exercises for Algorithm Development

The exercise contains a series of instructions for programming exercises that include mathematical calculations, selections, and iterations. The exercises range from calculating the double of a number to calculating the area of geometric figures.

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)
15 views5 pages

Programming Exercises for Algorithm Development

The exercise contains a series of instructions for programming exercises that include mathematical calculations, selections, and iterations. The exercises range from calculating the double of a number to calculating the area of geometric figures.

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

Programming exercises

SEQUENCE
1. Write an algorithm that calculates double of a given input number.
2. Write an algorithm that, given three real numbers X, Y, and Z, calculates the result of (X + Y + Z)2.
3. Write an algorithm that, given the price in euros as input, calculates its value in lire.
(N.B. 1 € = 1936.27 £).
4. Write the algorithm that, given an input time through its three components (hours,
minutes and seconds), calculate the total value in seconds.
5. Write an algorithm that calculates the area of a trapezoid, given the measurements of the bases and the height.
6. Write the algorithm that, given two numbers a and b (where a < b), calculates the width of the interval (a, b)
and the product of the extremes.
7. Write the algorithm that, given two integer numbers x and y, calculates the result and the remainder of the division.
interaction between x and y.

8. Write an algorithm that, given the ages of three people, calculates the average age.
9. Write an algorithm that, given the price of a product, calculates the price discounted by 20%.
10. Write an algorithm that, given the coordinates of two points in the plane, calculates the distance between them.
11. Write the algorithm that, given two strings, displays them in sequence (without intermediate spaces) and
communicate the length of the resulting string (only for the Visual programming course)
Basic)

SELECTION
12. Write the algorithm that, given a numerical value as input, tells whether it is positive or negative.
13. Write the algorithm that, when reading an integer input, determines if it is even or odd.
14. Write an algorithm that, given two integer inputs, checks if the first is a multiple of the second.
second.
15. Write an algorithm that, given an integer input, displays its double if it is even, the
triple if it is odd.
16. Write the algorithm that, given two numbers, calculates the sum if they are both positive, the product
otherwise.
17. Write an algorithm that, given the price of a product, applies a 12% discount if the price
is less than € 30.00, 25% otherwise.
18. Write the algorithm that, given the base and height of a triangle, calculates the area if they are both
positive, or print the message "Incorrect input values".
19. Write the algorithm that, given the endpoints a and b of an interval and a value x, displays the
messaggio "Il valore è interno all'intervallo" sea≤x≤b, altrimenti "Il valore è esterno
all'intervallo".
20. Write an algorithm that, given an input grade, determines if it is correct (between 1 and 10).
x 2
21. Write an algorithm that, given a real value x, calculates the value ; se of the function: y
x x 4 
a non-allowed value is entered, show the message 'Impossible'.
22. To write a algorithm what calculations he value of the function:
3
y 1
h x  if an invalid value is entered, show the message
z 1 x y
Impossible.
23. Scrivere l'algoritmo per controllare la correttezza di una data ricevuta in ingresso attraverso tre
various inputs: day, month and year; for simplicity, assume all months have 30 days.
1
24. Write the algorithm to check the correctness of a time received as input, through three
different inputs: h, m and s (in 24-hour format).
25. Write an algorithm that, given a user's water consumption, expressed in m3calculate the amount
of the bill, knowing that each bill includes a fixed fee of 20 euros and a share
variable of 2.50 euros/m3for the first 100 cubic meters of water, at 4.00 euros/m3for the cubic meters in
excess

SELECTION WITH NESTING


26. Write the algorithm that, given a numerical input value, determines if it is positive, negative, or zero.
27. Write the algorithm that, given the names of two football teams facing each other in a
match and the goals scored by both, announce the name of the winning team or indicate that the
the match ended in a draw.
28. Write the algorithm that, given 3 numbers as input, displays the greatest value.
29. Write the algorithm that, given 3 numbers as input, displays the smallest value.
30. Write the algorithm to display three numerical values received as input in ascending order.
31. Write the algorithm to display three numeric values received as input in descending order.
32. Write a program that reads from the keyboard the lengths of the three sides of a triangle and
determine if the triangle is equilateral, isosceles, right-angled or scalene.
33. Write an algorithm that helps a child learn the 4 basic operations. Take in
the two operands, the operator and the result and say if the result is right or wrong.
34. Write an algorithm that, given three integers, calculates:
a. the sum of those that are divisible by two or by five;
b. the product of those that are divisible by two and five;
c. the average of those that are not divisible by either two or five.
35. Write an algorithm that, given the coordinates of a point in the Cartesian plane, states in which quadrant it is located.
in which quadrant is the point located.
36. Given the equation ax + b = 0, with a and b input from the keyboard, write a program to determine
the value of x, if it exists, that solves the equation (WARNING: keep in mind that if a=0 and b≠0,
the equation is impossible; if a=0 and b=0, the equation is indeterminate.
37. A program should be created to solve quadratic equations. In particular, given a
generic quadratic equation in the form ax2+ bx + c = 0 where a, b, c are coefficients
real roots and x represents the unknown, the program determines the two roots x1ed x2of the equation
data, where they exist (WARNING: for the resolution it is necessary to consider the value of
discriminant Δ).
38. Si realizzi un programma che, dato il prezzo di un prodotto e la quantità acquistata, calcoli il
total price, taking into account that the seller applies a 10% discount if more than 5 are purchased
pieces, a 15% discount if more than 10 pieces are purchased or a 20% discount if more than 20 pieces are purchased.
39. Write a program that allows the user to choose between a triangle and a square and, depending on that,
of the choice, calculate the area.
40. The admission ticket to a museum has the following rates. For children under 6 years old
l'ingresso è gratuito (opzione 1), per gli studenti 8 euro (opzione 2), per i pensionati 10 euro
(option 3), for everyone else 15 euros (option 4). Create a program where the user inputs
a number between 1 and 4 is given and the price related to the chosen option is communicated. If the number is not
a valid option, an error message is displayed (with a critical icon).
41. Given a student's average, calculate the amount to be paid for enrollment in the following year.
knowing that this amount includes a fixed fee of € 18.00 and an additional fee of € 25.00 if
the average of the grades is less than 7, of € 17.50 if the average of the grades is between 7 and 8 and none
additional quota if the average grade is above 8. In the case where the family income is
below € 16,000.00, the final amount is reduced by 40%.

2
MULTIPLE CHOICE
42. Write an algorithm that, given an input value between 1 and 12, displays the name of the month
correspondent.
43. Write an algorithm that, given an input value between 1 and 12, indicates which quarter it belongs to.
of the year corresponds to the month.
44. Write the algorithm to convert an integer N between 1 and 365, provided as input, into
day and corresponding month. Consider a non-leap year.
45. The entrance ticket to a museum has the following prices. For children under 6 years old
The entrance is free (option 1), for students 8 euros (option 2), for retirees 10 euros (option 3)
3), for all the others 15 euros (option 4). Create a program where the user enters a number between
1 and 4 and the price related to the chosen option is communicated. If the number is not a valid option
An error message is displayed.
46. Write an algorithm that, given an input value between 1 and 12, indicates which part
the school year the corresponding month belongs to, considering that from September 1st to 31
December is the first quarter, from January 1 to June 30 is the second half-year and the remaining months.
they are classified as 'summer vacation'.

PRE AND POST CONDITIONAL ITERATION


47. Write an algorithm that displays the natural numbers from 1 to 20.
48. Write an algorithm that displays the natural numbers from 30 to 15 in descending order.
49. Write an algorithm that displays the odd natural numbers from 3 to 21.
50. Write an algorithm that displays the positive even numbers less than 50 in descending order.
51. Write an algorithm that displays the square of the natural numbers between 2 and 20.
52. Write an algorithm that displays the phrase 'Long live the holidays!' ten times.
53. Write an algorithm that displays a phrase chosen by the user 5 times.
54. Write an algorithm that displays a sentence chosen by the user, a number of times equal to the
length of the sentence (only for the Visual Basic programming course).
55. Write an algorithm that displays a sentence chosen by the user, a number of times equal to the value.
chosen by the user (if the number of times is negative, provide an appropriate error message).
56. Write an algorithm that displays all natural numbers less than the absolute value of a
number chosen by the user.
57. Write an algorithm that displays in increasing order all the natural numbers between two
numbers chosen by the user (extremes included).
58. Write an algorithm that displays in descending order all natural numbers between two
numbers chosen by the user (extremes included).
59. Write an algorithm that calculates the sum of the first 10 natural numbers.
60. Write an algorithm that calculates the sum of the first N natural numbers; ensure that N > 0.
61. Write an algorithm that, given 10 integers as input, calculates their sum.
62. Write an algorithm that, given 10 integers as input, calculates the arithmetic mean.
63. Write an algorithm that, given 15 integer inputs, tells how many even values have been entered.
64. Write an algorithm that, given 20 integer inputs, determines how many negative values there are.
inserted.
65. Write an algorithm that, given the input value N>0, calculates the sum of the first N numbers.
even positives.
66. Write an algorithm that, given N input values (N>0 chosen by the user), calculates how many values
positives have been entered.
67. Write an algorithm that, given N values (N>0 chosen by the user), calculates the percentage of
negative values entered.
68. Write an algorithm that, given the input value N>0, calculates the arithmetic mean of the first N.
positive odd numbers.
69. Write an algorithm that, given two input integers N and X (with N>0), displays the N
consecutive integers after X.
3
70. Write an algorithm that, given two integers N and X (with N > 0), displays the N
integer numbers preceding X in ascending order.
71. Write an algorithm that, given N integer values (N > 0) as input, calculates the sum of the numbers.
positive and the sum of the absolute values of the negative numbers.
72. Write an algorithm that, given N integer values (N > 0), calculates the sum of the numbers
negatives and the average of the positive numbers.
73. Write an algorithm that, given two natural numbers X and Y, sums the square roots of the numbers.
natural numbers between X and Y, endpoints included.
74. Write an algorithm that, given N integer values (N > 0) as input, calculates how many values are multiple
of 3.
75. Write an algorithm that, given N integer values (N > 0), calculates how many values are multiples.
of a number chosen by the user.
76. Write an algorithm that takes numeric values as input until the user enters the value 0 and
calculate the average.
77. Write an algorithm that takes numerical values as input as long as the user enters a value.
negative and calculate the sum of the square roots.
78. Write an algorithm that calculates the average age of a class of 20 students.
79. Write an algorithm that calculates the average of N grades of a student.
80. Write an algorithm that, given as input the number N (N > 0) of values and the threshold value S,
calculate the arithmetic mean of all input numbers that do not exceed the threshold value.
81. Calculate the product of two natural numbers, by means of successive sums.
82. Calculate the quotient and remainder of the division between two natural numbers, using differences.
successive.
83. Given the birth dates of N people, calculate how many of them were born in the month of
February.
84. Given the heights in meters of a group of Olympic athletes, calculate the average height and the number of
athletes shorter than one meter and seventy-five.
85. Given the amounts of money present at the closing in the 5 cash registers of a supermarket, calculate the
quantità di denaro totale presente e quantedi esse hanno una disponibilità inferiore a € 100,00.
86. Given a series of transactions of a bank account (income and expenses), calculate the balance.
final. If the balance is positive, add an active interest of 1.5%, otherwise charge a
passive interest of 3%. Finally, communicate the final balance.

ENUMERATIVE ITERATION
87. Write an algorithm that, given a number within the range [1, 10], displays its first
10 multiples.
88. Write an algorithm that displays the natural numbers from 300 to 150 in descending order.
89. Write an algorithm that displays the square of the natural numbers between 2 and 20.
90. Write an algorithm that displays the phrase 'Long live summer!' twenty times.
91. Write an algorithm that displays all natural numbers less than the absolute value of a
number chosen by the user.
92. Write an algorithm that displays in ascending order all natural numbers between two
numbers chosen by the user.
93. Write an algorithm that displays in descending order all natural numbers between two
numbers chosen by the user (enforce with mandatory input that the second number entered is
greater than or equal to the first).
94. Write an algorithm that calculates the sum of the first 10 natural numbers.
95. Write an algorithm that calculates the sum of the first N natural numbers; ensure that N > 0.
96. Write an algorithm that takes 10 values as input and calculates the arithmetic mean.
97. Write an algorithm that, given 25 integer values as input, tells how many even values were entered and
how many negative values have been entered.
98. Write an algorithm that, given the input value N>0, calculates the sum of the first N numbers.
positive even.
4
99. Write an algorithm that, given N values (N>0) as input, calculates how many positive values have been provided.
inserted and the percentage of negative values entered.
100. Write an algorithm that, given two integer inputs N and X (with N>0), displays the N
successive integers to X.
101. Write an algorithm that, given two integers N and X (with N>0), displays the N
integer numbers preceding X.
102. Write an algorithm that, given two positive natural numbers X and Y, sums the square roots of
natural numbers between X and Y, extremes included.
103. Write an algorithm that, given N integer values (N>0), calculates how many values are multiples.
of a number chosen by the user.
104. Write an algorithm that, given the input number N (N>0) of values and the threshold value S, calculates
the arithmetic mean of all input numbers that exceed the threshold value.

SUMMARY EXERCISES
105. Given the number of receipts from a merchant's day, calculate the percentage of purchases
less than €10.00 and the average value of purchases.
[Link] the sales target and the collections made by a merchant, calculate whether the target is met.
state reached and, if not, calculate how much the merchant still needs to collect for
reach the goal.
[Link] the quantity and unit price of N types of products sold, calculate the total revenue and the
total number of products taken from the warehouse.
108. Given the names of two athletes and the scores obtained by both in 10 trials, declare the winning athlete.
to communicate the situation of 'equal merit'. Each score must have an integer value.
ranging from 1 to 10; the winner is the one who achieves the highest overall score.
109. Given the scores obtained collectively by 15 athletes, calculate the average score, how many have
obtained an equal score and the percentage of scores below average; store the data in a
object of type ListBox (only for the Visual Basic programming course).
110. Given the subjects and the final grades obtained in each subject at the end of the school year, calculate
the overall average and the number of failures. Therefore showing the outcome of the school year,
considering that without failures you are promoted in June, with less than 4 failures you are
you obtain a suspension of the judgment, otherwise you fail.
Given the names and ages of your friends on a social network, calculate the overall average age and
display the names of friends with ages above average; then calculate the percentage of
friends still underage; for the solution use two ListBox type objects, one for the names and
one for the ages of friends (only for the Visual Basic programming course).

You might also like