Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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
Source by www.javatpoint.com #
 
PREVIOUS NEXT
Tagged: #How #swap #numbers
ADD COMMENT
Topic
Name
2+9 =