Search
 
SCRIPT & CODE EXAMPLE
 

CPP

swap two numbers

int a=4;
int b=5;
a=a+b; // 4 + 5 = 9
b=a-b; // 9 - 5 = 4
a=a-b; // 9 - 4 = 5
Comment

swapping of two numbers

 #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;  
}  
Comment

How to swap two numbers

// 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
Comment

Swapping Two Numbers Using Third Variable

   public static void main(String[] args) {
        int x = 10;
        int y = 20;
        int temp;

        temp = x;
        x = y;
        y = temp;

        System.out.println("x:"+x  +" y:" + y);
    }
Comment

swap two numbers

    public static void main(String[] args) {
        int x = 10;
        int y = 20;
        
        x=x+y;
        y=x-y;
        x=x-y;

        System.out.println("x:"+x+" y:"+y);
    }
Comment

swap two number

Route::get('/foo', function (AppFoo $foo) {
    return $foo->hello(); // Hello World
});
Comment

PREVIOUS NEXT
Code Example
Cpp :: check if a string is palindrome cpp 
Cpp :: matrix in vector c++ 
Cpp :: c++ remove last character from string 
Cpp :: C++ String Copy Example 
Cpp :: sort index c++ 
Cpp :: check if whole string is uppercase 
Cpp :: c++ loop vector 
Cpp :: deque c++ 
Cpp :: what is c++ standard library 
Cpp :: why is using namespace std a bad practice 
Cpp :: factorial function c++ 
Cpp :: how to sort in c++ 
Cpp :: swap elements array c++ 
Cpp :: c++ casting 
Cpp :: modulo subtraction 
Cpp :: cpp vs c# 
Cpp :: unique_ptr syntax 
Cpp :: vector to string cpp 
Cpp :: remove element from vector 
Cpp :: c include 
Cpp :: Converting to string c++ 
Cpp :: How to get cursor position c++ 
Cpp :: reversing a string in c++ 
Cpp :: c++ split string by space into array 
Cpp :: c++ syntax 
Cpp :: C++ :: 
Cpp :: c++ function of find maximum value in an array 
Cpp :: overload subscript operator cpp 
Cpp :: put text on oled 
Cpp :: C++ program for Celsius to Fahrenheit and Fahrenheit to Celsius conversion using class 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =