Lesson #5. IF statement Part II. Max and Min
Follow the rules:
- Save your files with the names of the task (e.g. task-04.pas)
- Give meaning names to your variables
- Use the comments to make the program clear for user
- Give the task of the program in the form of a comment before the program code. For comments use curly brackets:
- Give the results of your program (log) in the form of a comment after the program code. It’s easy to do by simply copying. For comments use curly brackets:
Search for minimum and maximum
- Which of the two variables is greater:
- Which of the two variables is greater and which one is less:
Make the task number 0
(task-00-if.pas
).
Make the tasks number 01
and 02
(task-01-if.pas
, task-02-if.pas
).
Random function
Random function is often used in Pascal.To generate numbers from 0
to n
not including the value of n
itself (integers in the interval [0,N)), you must write:
random (n);
To get random number in range from a
to b
use the formula:
x:=random(b-a+1)+a;
Tasks
0. {0.3 points} [task-00-if.pas]
Three integers are given. Find the maximum (the greatest) number among the three entered numbers.
1.{0.3 points} [task-01-if.pas]
Two real numbers are given. Find the maximum (the greatest) and minimum
(the least) number among them. Output max and min.
-5.2, 74.6 >>> max=74.6, min=-5.2 25.7, 14.7 >>> max=25.7, min=14.72.
{0.3 points} [task-02-if.pas]
A two-digit number is given. Find the minimum and the maximum among its digits and swap the digits in the number.Example:
74 >>> max = 7, min = 4, swapped = 47 25 >>> max = 5, min = 2, swapped = 523.
{0.3 points}[task-03-if.pas]
For given real numbers a and b find the value of the following function y
. For y
use real variable:4. {0.3 points}[task-04-if.pas]
For a given real x find the value of the following function f
. For f
use real variable:
5. {0.4 points}[task-05-if.pas]
For a given real x find the value of the following function f
:
6. {0.4 points}[task-06-if.pas]
The integers a, b, c are given, which are the sides of a tríangle. Print True
if the triangle with sides a, b, c is isósceles (равнобедренный), and print False
otherwise.
7. {0.5 points}[task-07-if.pas]
An integer is given. 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.
Example:
-5 >>> negative odd number 6 >>> positive even number
8. [task-08-if.pas]
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.
9. [task-9-if.pas]
The coordinates X
and Y
of the chessboard field are given (integers lying in the range of 1–8). 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.
10. {0.8 points}[task-10-if.pas]
Three integers are given. Find the number (quantity) of positive numbers among them. Example:
-1, -18, -9 >>> 0 -4, -8, 12 >>> 1 0, 11, 2 >>> 2 7, 15, 1 >>> 3Note. It is convenient to use an auxíliary variable of integer type.
11. {0.8 points}[task-11-if.pas]
Three integers are given. Find the number (quantity) of numbers among them that match the inequality 10 < numb < 20
. Example:
-1, -18, 11 >>> 1 5, 17, 12 >>> 2 0, 9, 7 >>> 0
12. {0.8 points}[task-12-b.pas]
Three real numbers are given. 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, give the log of the program in the form of a comment.
-1, -18, -9 >>> True -4, -8, 12 >>> False 0, -11, -2 >>> True 0, 0, 0 >>> True 7, 15, -1 >>> False
Extra tasks:
13. {1.2 points}[task-13-extra-b.pas]
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.
A = 15, B = 17, k = 2 >>> 17, 15, True A = 6, B = -2, k = 5 >>> 6, -2, False A = 11, B = 11, k = 0 >>> 11, 11, True A = 15, B = 16, k = 0 >>> 16, 15, False
14.{0.3 points} [task-14-extra-if.pas]
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.
input: 374 => output: min=3, max=7, swapped number=734
15. {0.8 points} [task-15-extra-if.pas]
Three
integers are given. Find the maximum (the greatest) number and minimum
(the least) among the three entered numbers. Output max
and after it output min
.
Note. Try to use as few comparison operations as possible. Use the output operator only once - at the end of the program, for this you need to memorize the desired numbers in additional variables.
Example:input: -5, 74, 3 output: -5, 74 input: 3, 0, 0 output: 0, 3 input: 25, -100, 14 output: -100, 25
Extra task 2:
1. {0.8 point}[extra-task-01-if-b.pas]
Two integer - the coordinates of the point on the plane are given. Print 0 if the point coincides with the (0,0)
coordinate. If the point does not coincide with the the (0,0)
coordinate, but lies on the OX
or OY
axis, print 10 or -10, respectively. Print 11 if the point does not lie on the coordinate axes.
Note. Implement the program so that the output operator is used only once to output a number that describes the position of a point on the coordinate plane.
2. {0.8 point}[extra-task-02-if.pas]
For given real x
find the value of the following function f
the argument of which is an integer:
3. {1 point}[extra-task-01-if-b.pas]
The integers a
, b
, c
are given. Print True
if there is a triangle with the corresponding lengths of the sides and print False
otherwise. If the triangle exists so print its area.
S=√p(p−a)(p−b)(p−c)