Labs and Tasks: Functions
Требуемые условия завершения
Открыто с: воскресенье, 17 августа 2025, 00:00
Срок сдачи: воскресенье, 24 августа 2025, 00:00
Привожу весь указанный вами текст в формате HTML с встроенными стилями CSS в атрибутах тегов, сохраняя оригинальную структуру и форматирование:
html
Functions
Functions
Lab 1, Functions:
To do: Find the maximum among two numbers using a function.
✍Algorithm:
function max(a, b: integer): integer;
begin
if a > b then Result := a
else Result := b;
end;
begin
var (x, y) := readinteger2;
println('maximum = ', max(x, y))
end.
{0.3 points} Task 1, functions:
To do: Create a function to find the minimum among three numbers (three parameters of the function).
Expected output:
please, input three numbers
>>>2 >>>5 >>>9
minimum = 2
[Program name: task-01-func.pas]
{0.3 points} Task 2, functions:
To do: Create a function to find the average (arithmetic mean) of three entered numbers (three parameters).
Expected output:
please, input three numbers
>>>2 >>>5 >>>2
average = 3
[Program name: task-02-func.pas]
{0.3 points} Task 3, functions:
To do: Create a function IsDigit(D)
that returns true
if the entered integer D
is a digit (i.e., lies in the range [0,9]). In the main program, output the results of this function for three entered numbers.
Expected output:
please, input number #1
42
false
---
please, input number #2
4
true
---
please, input number #3
-5
false
[Program name: task-03-func.pas]
Lab 2, Functions:
To do: Create a function to calculate the factorial of an entered number.
✍Algorithm:
function Fact(n: integer): integer;
begin
Result := 1;
for var i := 1 to n do
Result *= i
end;
begin
var x:=readinteger('enter number:');
println($'{x}! = {Fact(x)}')
end.
{0.4 points} Task 4, functions:
To do: Create a function that calculates the sum of all numbers from 1 to N. N is a function parameter.
Expected output:
Enter the number N:
100
the sum = 5050
[Program name: task-04-func.pas]
Lab 3, Short Function Definition:
To do: Create a function to calculate the hypotenuse of a triangle (sides of the triangle are entered). Use this function to calculate the hypotenuses of five triangles.
✍Algorithm:
function Hypot(a, b: real) := Sqrt(a * a + b * b);
begin
loop 5 do
begin
var (a, b) := ReadlnReal2('Enter sides a,b:');
Println(Hypot(a, b))
end;
end.
{0.4 points} Task 5, functions:
To do: Create a function CircleS(R)
of real type that returns the area of a circle with radius R
(R is entered real). Use this function to find the area of three circles with these radii. The area of a circle of radius R is calculated by the formula S=π*R²
. As the value of π (π), use 3.14. Use short function definition.
Expected output:
Enter radius
>>>5
S =
---
Enter radius
>>>7.8
S =
[Program name: task-05-func.pas]
{0.4 points} Task 6, functions:
To do: Create a function that calculates the power of a number. Base number and exponent are the parameters of the function. Use short function definition.
Note: Remember that parameters of the power()
function are reals.
Expected output:
Enter number and exponent:
>>>5 >>>2
5 ^ 2 = 25
[Program name: task-06-func.pas]
{0.5 points} Task 7, functions:
To do: Create a function Triangle(a, h)
that calculates the perimeter of an isosceles triangle based on its base a
and height h
dropped onto the base (a and h are entered integers). When calling this function, output the perimeters of three triangles (perimeter = sum of the lengths of all sides). To find the side b
of the triangle, use the Pythagorean theorem: b²=(a/2)²+h²
.
Expected output:
Enter a and h
>>>5 >>>2
perimeter = 11.40
[Program name: task-07-func.pas]
{0.3 points} Task 8, functions:
To do: Extend the previous task (#7) by creating an overloaded version of the function to calculate the perimeter of an isosceles triangle for real values of a
and h
. Call this function twice — once for integer arguments and once for real arguments.
Expected output:
Enter a and h
>>>5 >>>2
perimeter = 11.40
---
Enter a and h
>>>2.5 >>>6.8
perimeter = 16.33
---
Enter a and h
>>>15.2 >>>18.3
perimeter = 54.83
[Program name: task-08-func.pas]
Теперь у вас аккуратно оформленный и подготовленный HTML-документ.