368d6fafea
Code backup
30 lines
688 B
C++
30 lines
688 B
C++
// C++ Swap Number
|
|
#include <iostream>
|
|
using namespace std;
|
|
|
|
int main()
|
|
{
|
|
int a = 5, b = 10, c = 5, d = 10, temp;
|
|
|
|
cout << "Swap Numbers (Using Temporary Variable)" << "\nBefore swapping." << endl;
|
|
cout << "a = " << a << ", b = " << b << endl;
|
|
|
|
temp = a;
|
|
a = b;
|
|
b = temp;
|
|
|
|
cout << "\nAfter swapping." << endl;
|
|
cout << "a = " << a << ", b = " << b << endl;
|
|
|
|
cout << "\nSwap Numbers Without Using Temporary Variable" << "\nBefore swapping." << endl;
|
|
cout << "a = " << c << ", b = " << d << endl;
|
|
|
|
c = c + d;
|
|
d = c - d;
|
|
c = c - d;
|
|
|
|
cout << "\nAfter swapping." << endl;
|
|
cout << "a = " << c << ", b = " << d << endl;
|
|
|
|
return 0;
|
|
} |