Swapping of Two Numbers
In this program, You will get the program code for Swapping of Two Numbers using Third Variable in C programming.
What is Swapping
Swapping is the process of exchanging the values of two variables. Swapping is a common technique for sorting data. It is also used to exchange values between different processes or threads.
How to swap two numbers
Swap two numbers means that the values of the two variables are exchanged with each other. This program can be done by using third variable and swap without using third variable. Here we are doing this program by using third variable.
Swapping of Two Numbers in C program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | //Swapping of Two Numbers in C #include <stdio.h> int main() { int x, y, temp; printf("\nEnter the value of x and y\n"); scanf("%d%d", &x, &y); printf("\nBefore Swappingnx = %d\ny = %d\n", x, y); temp = x; x = y; y = temp; printf("\nAfter Swappingnx = %d\ny = %d\n", x, y); return 0; } |
Output
Check out our other C programming Examples