The program is written to swap two values. A third variable is used here to swap the two numbers. First, one number is stored in a temporary variable. Then the 2nd number is copied to the 1st number and the previously stored first number is stored in the 2nd variable and hence the values are exchanged.

If the two variables are a and b whose values are to be exchanged and the values are:

a = **5**, b = **6**

Then, after exchanging the values will be:

a = **6**, b = **5**

**For example,**

INPUT: Two Numbers

OUTPUT: The values after exchanging

PROCESS:

Step 1: [Taking the inputs]

Read a, b [two numbers]

Step 2: [Swapping the two values]

Set tmp<-a

Set a<-b

Set b<-tmp

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 the program.

__SPACE COMPLEXITY:__

The space complexity is **O(1)** as it requires a constant number of memory spaces to execute the program for any given input.

Related

- Largest Number of two numbers
- largest number between two or three numbers
- Find Largest Number by Menu Driven
- Even and Odd numbers
- Swapping values without third variable
- 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