xxxxxxxxxx
// Method 1: With temporary variable
temp = A
A = B
B = temp
// without temporary variable
// Method 2: Addition and subtraction
A = A + B
B = A - B
A = A - B
// Method 3: Muitply and Divide
A = A * B
B = A / B
A = A / B
xxxxxxxxxx
#include <iostream>
using namespace std;
int main()
{
int a=5, b=10;
cout<<"Before swap a= "<<a<<" b= "<<b<<endl;
a=a*b; //a=50 (5*10)
b=a/b; //b=5 (50/10)
a=a/b; //a=10 (50/5)
cout<<"After swap a= "<<a<<" b= "<<b<<endl;
return 0;
}
xxxxxxxxxx
#include<stdio.h>
int main()
{
int x = 20, y = 30, temp;
temp = x;
x = y;
y = temp;
printf("X = %d and Y = %d", x, y);
return 0;
}
xxxxxxxxxx
num1 = input("Enter first number: ")
num2 = input("Enter second number: ")
print("Value of first number before swapping is" , num1)
print("Value of second number before swapping is" , num2)
store_flag = num1
num1 = num2
num2 = store_flag
print("Value of first number after swapping is" , num1)
print("Value of second number after swapping is" , num2)
xxxxxxxxxx
Route::get('/foo', function (App\Foo $foo) {
return $foo->hello(); // Hello World
});