Labs and Tasks
{0.3 points}
Task 1:
To do: Three integers are entered (they should be in the range from 0 to 10). Find the maximum (the greatest) number among the three entered numbers. Check entered values using assert function.
Expected output:
please enter three integer numbers >>> 6 >>> 1 >>> 9 The maximum number is 9 please enter three integer numbers >>> 1 >>> 2 >>> 13 Incorrect input! must be in the range from 0 to 10
[Program name: L5task01.pas]
{0.3 points}
Task 2:
To do: Two real numbers are given. Find a maximum (the greatest) and minimum (the least) number among them. Output max and min.
Expected output:
please enter three integer numbers >>> 3.0 >>> 55.5 Maximum number: 55.5 Minimum number: 3.0
[Program name: L5task02.pas]
{0.5 points}
Task 3:
To do: A two-digit number is given. Find the minimum and the maximum among its digits and swap the digits in the number. Check entered values using assert function (it should be two-digit number).
Expected output:
please enter two-digit number >>> 74 max = 7, min = 4, swapped = 47 please enter two-digit number >>> 7 Incorrect input! should be two-digit number
[Program name: L5task03.pas]
{1 point}
Task 4:
To do: The integers A, B and k are given. At first output the larger of A and B, then the lesser of them. Print True if the difference between the numbers does not exceed the value of k and print False otherwise. Check the correctness of your program with at least three input data sets, give the log of the program in the form of a comment.
Expected output:
Please enter three integer numbers >>> 3 >>> 5 >>> 2 5 3 True Please enter three integer numbers >>> 44 >>> 20 >>> 9 44 20 False
[Program name: L5task04.pas]
{1 point}
Task 5:
To do: A three-digit integer is given. Find the maximum (the greatest) digit and minimum (the least) digit among the three digits of the given number and swap them. Output the numbers. Check entered values using assert function (it should be three-digit number).
Expected output:
please enter three-digit integer >>> 167 After swaping maximum and minimum we have: 761 please enter three-digit integer >>> 7 Incorrect input! should be three-digit number
[Program name: L5task05.pas]
{0.4 points}
Task 6:
To do: For a given real x find the value of the following function f.
Expected output:
please enter a real number >>> -4 The result of function f is 4 --- please enter a real number >>> 1.5 The result of function f is 2.25
[Program name: L5task06.pas]
{0.3 points}
Task 7:
To do: An integer is given. Use random function to generate this number. Display its description in the following form: “negative even number” or “negative odd number” or “zero number” or “positive odd number” or “positive even number”. Check the correctness of your program, provide a log of the program in the form of a comment.
Expected output:
generated number: -4 negative even number --- generated number: -3 negative odd number
[Program name: L5task07.pas]
{0.4 points}
Task 8:
To do: The numbers X and Y are given. Print True if the point with coordinates (X, Y) lies in the fourth coordinate quarter and print False otherwise. Do not use conditional if statement.
Expected output:
Please enter the values of x and y >>> 8 >>> -4 True --- Please enter the values of x and y >>> -9 >>> 3 False
[Program name: L5task08.pas]
{0.4 points}
Task 9:
To do: The coordinates X and Y of the chessboard field are given (integers lying in the range of 1–8). Use random function to generate these numbers. Considering that the bottom left cell of the board (1, 1) is black, output True if the field of X and Y is white and print False otherwise.
Expected output:
Please enter the values of x and y between 1 and 8 inclusive 2 7 False --- Please enter the values of x and y between 1 and 8 inclusive 3 5 True
[Program name: L5task09.pas]
{0.3 points}
Task 10:
To do: Three integer numbers are given. Use random function to generate these numbers. Print true if none of these numbers are positive and False otherwise. Check the correctness of your program with at least three input data sets.
Expected output:
generated numbers: -9 -6 -49 True --- generated numbers: 0 77 -5 False
[Program name: L5task10.pas]
{0.3 points}
Task 11:
To do: Integers x, y are given. Calculate the value of the function.
A snippet of code:
begin var x, y: integer; // arguments of f function Write('Input integers x, y: '); Readln(x, y); var f: integer; // TODO: set the value of the function f(x, y) to f variable WritelnFormat('f({0}, {1}) = {2}', x, y, f); end.
Expected output:
Input integers x, y: >>> 7 >>> -5 f (7, -5) = 70
[Program name: L5task11.pas]
Tasks for self-solving
Note: tasks should be saved in a file with the name of the task, and be sure to insert a comment with the statement of the task in the code.
BOOLEAN
Boolean4.
Given two integers A and B, verify the following proposition: «The inequalities A > 2 and B ≤ 3 both are fulfilled».
Expected output:
<< A = 1 B = 2 results: false
Boolean5.
Given two integers A and B, verify the following proposition: "The inequality A ≥ 0 is fulfilled or the inequality B < −2 is fulfilled".
Expected output:
<< A = 0 B = -3 results: true
Boolean6.
Given three integers A, B, C, verify the following proposition: "The double inequality A < B < C is fulfilled".
Expected output:
<< A = 50 B = 66 c = 73 results: true
Boolean7.
Given three integers A, B, C, verify the following proposition: "The number B is between A and C".
Boolean17.
Given a positive integer, verify the following proposition: "The integer is a three-digit odd number".
Boolean18.
Verify the following proposition: "Among three given integers there is at least one pair of equal ones".
Expected output:
<< -1 -5 3 results: false
IF
If4.
Three integers are given. Find the amount of positive integers in the input data.
Expected output:
<< -10 -7 -11 results: 0
If6.
Given two real numbers, output the larger value of them.
If13.
Given three real numbers, output the value between the minimum and the maximum.
If15.
Given three real numbers, output the sum of two largest values.
If24.
Given a real independent variable x, find the value of a real function f defined as: f(x) = 2·sin(x), if x > 0, 6 − x, if x ≤ 0.
Expected output:
<< x = 6.05 results: -0.46
If26.
Given a real independent variable x, find the value of a real function f defined as: −x, if x ≤ 0, f(x) = x², if 0 < x < 2, 4, if x ≥ 2.
Expected output:
<< x = 1.05 results: 1.10