Begin 22. Поменять местами содержимое переменных \(A\) и \(B\) и вывести новые значения \(A\) и \(B\).

Решение на Python 3

import random

A,B = sorted(random.sample(range(-10, 10), 2))
print("A = {0}, B = {1}".format(A,B))

A,B = B,A
print("A = {0}, B = {1}".format(A,B))

A = B + A
B = A - B
A = A - B
print("A = {0}, B = {1}".format(A,B))

X = B
B = A
A = X
print("A = {0}, B = {1}".format(A,B))

Решение на C++

#include <iostream>
using namespace std;
int main(){
double A,B,x;

cout << "Vvedite znacheniye peremennoy A: ";
cin >> A;
cout << "Vvedite znacheniye peremennoy B: ";
cin >> B;
x = A;
A = B;
B = x;
cout << "Perviy sposob: " << endl;
cout << "A: " << A << endl;
cout << "B: " << B << endl;

cout << "Vvedite znacheniye peremennoy A: ";
cin >> A;
cout << "Vvedite znacheniye peremennoy B: ";
cin >> B;
A = A+B;
B = A-B;
A = A-B;
cout << "Vtoroy sposob: " << endl;
cout << "A: " << A << endl;
cout << "B: " << B << endl;
return 0;
}