C Program to Swap Two Numbers without using Temporary Variable
Program
#include<stdio.h>
#include<conio.h>
int main()
{
int a, b;
clrscr();
printf("Enter value of a: ");
scanf("%d", &a);
printf("Enter value of b: ");
scanf("%d", &b);
printf("Before swapping: a = %d and b = %d\n", a, b);
a = a + b;
b = a - b;
a = a - b;
printf("After swapping: a = %d and b = %d", a, b);
getch();
return(0);
}
Output of the above program :
Enter value of a: 23 ↲ Enter value of b: 17 ↲ Before swapping: a = 23 and b = 17 After swapping: a = 17 and b = 23 Note: ↲ indicates ENTER is pressed.