Write a program in c to swap two numbers

First, define one macro SWAP. He is a software professional post graduated from BITS-Pilani and loves writing technical articles on programming and data structures. You might also like :. Try to run the program and drop one comment below if you have any queries.

c program to swap two numbers without using third variable using functions

This trick helps in swapping the numbers. Thanks for reading! It will return 7, which gets assigned to n1. We are using the bitwise operator to swap these numbers.

With this program, you will learn how to swap two numbers without using a third number using a bitwise operator and using a macro. You can also use one method and move the code to it.

swapping of two numbers in java

Ask the user to enter the first number. So, till now one number got swapped.

C program to swap two numbers using functions

Thanks for reading! You can also use one method and move the code to it. Finally, print out both numbers. Ask the user to enter the first number. You might also like :. This trick helps in swapping the numbers. It will return 7, which gets assigned to n1. This will take two numbers a and b and swap them using bitwise operator. It will return 5, which gets assigned to n2. Instead of using a third variable, we can write just one line to swap two variables. He is a software professional post graduated from BITS-Pilani and loves writing technical articles on programming and data structures. So, till now one number got swapped. This solution only works for unsigned integer types.
Rated 10/10 based on 31 review
Download
Write a c program to swap two numbers using function