C Program to Swap Two Numbers using Temp/Third Variable
/* C Program to Swap Two Numbers using Temp/Third Variable */
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include <stdio.h> main() { int a, b, temp; printf("\n Enter the values of a and b: "); scanf("%d %d", &a, &b); // Taking The values of x and y from user printf("\n Before Swapping: \n a = %d b = %d \n",a,b); temp = a; //temp stores value of a a = b; //a stores b value b = temp; //b stores temp value printf("\n After Swapping: n a = %d b = %d \n",a,b); return 0; } |
Output: ( using GNU GCC Compiler with Code Blocks IDE )