C Program To Swap Two Numbers using Temporary Variable
Learn How To Swap Two Numbers using Temporary Variable in C Programming Language. Learn C Code To Swap Two Variables using using Third variable. Two variables can be swapped using Third variable which is demonstrated below.
Also Read: C Program To Swap Two Variables without using Temporary (Third) Variable
C Program To Swap Two Numbers using Temporary Variable
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #include<stdio.h> int main() { int num1, num2, temp; printf("\nEnter The First Number:\t"); scanf("%d", &num1); printf("\nEnter Second Number:t"); scanf("%d", &num2); temp = num1; num1 = num2; num2 = temp; printf("\nThe Swapped Values are:\n"); printf("First Number = %d and Second Number = %d\n", num1, num2); return 0; } |
Also Read: C Program To Swap Two Variables using Call By Reference
Output

Also Read: C Program To Swap Two Variables using Call By Value
If you have any compilation errors or doubts in this C Program To Swap Variables using Third Variable, let us know about it in the Comment Section below.