The program is written here to swap the values of two numbers without using a third variable. The process of swapping two values without using a third variable is shown below with an example.

Let a = 5 and b = 6 and the values of a and b are to be swapped.

**a = a + b = 5 + 6 = 11**

**b = a - b = 11 - 6 = 5**

**a = a - b = 11 – 5 = 6**

Therefore, after this **a = 6 **and **b = 5**.

INPUT: Two Numbers

OUTPUT: The numbers after exchanging the values

PROCESS:

Step 1: [Taking the inputs]

Read a, b [two numbers]

Step 2: [Swapping the two values]

Set a<-a+b

Set b<-a-b

Set a<-a-b

Print "After swapping the values are a and b"

Step 3: Stop.

__TIME COMPLEXITY:__

The time complexity of this program is **O(1)** as it requires a constant time to execute for any given input.

__SPACE COMPLEXITY:__

The space complexity of this program is **O(1)** as it requires a fixed number of memory spaces to execute the program.

Related

- Largest Number of two numbers
- largest number between two or three numbers
- Find Largest Number by Menu Driven
- Even and Odd numbers
- Swapping Two Values
- Leap Year
- Basic Calculator
- Farenheit to Celsius
- ASCII value
- Average Of Numbers
- Average of Even Numbers
- Average Of Odd Numbers
- Sum of n Numbers
- Sum of n Natural Numbers
- Factorial
- Factorial with Recursion
- Multiplication Table
- Exponential without function
- Number Reverse
- String Reverse
- Fibonacci series
- Fibonacci Series with recursion
- Prime Number
- Prime Numbers between 1 and 100
- Prime Numbers in a given range
- Twin Prime
- Twin Prime Range
- Prime factors of a number
- Prime Factors of range of Numbers
- LCM of N numbers
- GCD of N numbers
- Sum of the digits
- Palindrome Number
- Armstrong Number
- Binary to Decimal
- Binary to Octal
- Binary to HexaDecimal
- Decimal to Binary
- Decimal to Octal
- Decimal to Hexadecimal
- Hexadecimal to Binary
- Hexadecimal to Octal
- Hexadecimal to Decimal
- Octal to Binary
- Octal to Hexadecimal
- Octal to Decimal
- Sorting an Array
- Remove Duplicate Elements from an Array
- Left Rotate of an Array
- Right Rotate by 2 of an Array