C Program To Swap Two Numbers Using Three Numbers – If you are looking for swapping C program, this article will guide you to lean swapping two numbers in C using 3 variables. Just go through this swapping tutorial you will able write a program to swap two numbers using three variable a,b and c.
We are publishing series of C programs for beginners, students, B.Tech graduates to enhance their C programming skills and hands-on experience on coding. This is the second C programming example in the series, it helps newbies in reaching their goals in the career. All the best guys in learning c programming with coding compiler blog.
C Program To Swap Three Numbers
Swapping in C programming language can be done using various techniques, like using two variables, three variables, and functions, but here in this swapping program, we used three variables to perform swap two numbers in C.
C Program To Swap Three Numbers Source Code
Copy paste the below source code or write your own logic into C compilers and run the program to see the result.
/* Swapping 2 Using Three Variables In C - SWAPTWONUMBERS.C */ #include<stdio.h> #include<conio.h> void main() { int a, b, c ; clrscr() ; printf("Enter two numbers : ") ; scanf("%d %d", &a, &b) ; printf("\nBefore swapping : \n\n") ; printf("a = %d \t b = %d", a, b) ; /* Swapping Two Numbers Logic */ c = a ; a = b ; b = c ; printf("\n\nAfter swapping : \n\n") ; printf("a = %d \t b = %d", a, b) ; getch(); }
C Program To Swap Two Numbers Output
After you compile and run the above program, your C compiler asks you to enter two numbers to swap, then it will show output before swapping and after swapping two numbers like below expected output.
Enter two numbers: 10 20
Before swapping :
a = 10 b = 20
After swapping :
a = 20 b = 10
Read Other C Programming Tutorials:
C Program To Swap Two Numbers Using Two Variables
C Program To Swap Two Numbers Using Three Variables
C Program To Swap Two Numbers Using Two Variables