Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Замена двух переменных местами
- */
- // 1. С помощью третьей переменной
- #include <iostream>
- using std::cout;
- using std::cin;
- using std::endl;
- #define TAB '\t'
- void main()
- {
- setlocale(0, "");
- int a = (cout << "Введите значение певой переменной -> ", cin >> a, a);
- int b = (cout << "Введите значение второй переменной -> ", cin >> b, b);
- int temporary;
- cout << endl << "Значение первой переменной: " << a << endl;
- cout << "Значение второй переменной: " << b << endl << endl;
- temporary = a;
- a = b;
- b = temporary;
- cout << "Значение первой переменной после перестановки: " << a << endl;
- cout << "Значение второй переменной после перестановки: " << b << endl;
- }
- /*
- //2. Без помощи третьей переменной
- #include <iostream>
- using std::cout;
- using std::cin;
- using std::endl;
- void main()
- {
- setlocale(0, "");
- int a, b;
- cout << "Введите две переменные -> "; cin >> a >> b;
- a = a + b;
- b = a - b;
- a = a - b;
- cout << "Вы ввели:\n" << a << "\t" << b << endl;
- cout << "Переменные поменяны местами:\n" << a << "\t" << b << endl;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement