Issue
Code backup
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// 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;
|
||||
}
|
||||
Reference in New Issue
Block a user