# Write a program that exchanges the values of the variables x and y if x is greater than y.

September 28, 2021 | education

| Let’s write a program that exchanges the values of the variables x and y if x is greater than y.

To do this, we need to introduce an additional variable z to store the value of one of the variables.

program 1;

var x, y, z: integer;

begin

writeln (‘Enter the values of the variables x and y’);

readln (x, y);

if x> y then

begin

z: = x;

x: = y;

y: = z;

writeln (‘x =’, x);

writeln (‘y =’, y);

end;

end.

Let’s check the operation of this program in two ways:

1) Let x = 5; y = 4.

Then the program compares the values of x and y (5> 4) and proceeds to the next step:

z = 5, x = 4, y = 5.

And it will display: x = 4, y = 5.

2) Let x = 3; y = 4.

Then the program, comparing the values of x and y (3 <4), will stop its further calculation.

One of the components of a person's success in our time is receiving modern high-quality education, mastering the knowledge, skills and abilities necessary for life in society. A person today needs to study almost all his life, mastering everything new and new, acquiring the necessary professional qualities.