C program to swap two numbers without using third variable
Output:
Enter two numbers to swap:
4 5
Before swapping:
a=4 b=5
After swapping:
a=5 b=4
Implementation:
Output:
Enter two numbers to swap:
4 5
Before swapping:
a=4 b=5
After swapping:
a=5 b=4
Implementation:
#include <stdio.h>
int main(void) {
int a,b;
printf("Enter two numbers to swap:\n");
scanf("%d %d",&a,&b);
printf("Before swapping:\n");
printf("a=%d b=%d\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("After swapping:\n");
printf("a=%d b=%d",a,b);
return 0;
}