How to Swap two numbers in C | Learn C

Swap two numbers

swap two numbers
Swapping means changing the order of the numbers.
Like A = 12, B = 15
becomes A = 15, B = 12
There are many ways to do that, I'll cover most frequent of them.
  • Using 3rd Variable.
  • Without Using 3rd Variable.
  • Using a function and pointer.

🔆Using 3rd Variable:

Q. Write a program to swap two variables using 3rd variable.
A. 

🔆Without using 3rd Variable:

Q. Write a program to swap two variables without using 3rd variable.
A. 

🔆Using function:

Q. Write a program to swap two variables using function.
A. 

Thanks for reading. 🙏
If you liked it feel free to share with your dear ones.💗
And tell me what do you think in the comment box.💬

Post a Comment

أحدث أقدم