# Swap values of 2 variables without using 3rd variable C Program

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
/*WAP to swap values of 2 variables without using 3rd variable */ #include<stdio.h> void main() { int a,b; clrscr(); printf("Enter The Value for A & B\n"); scanf("%d%d",&a,&b); printf("Values Before Swapping A & B \n"); printf("A=%d \t B=%d \n",a,b); a=a+b; b=a-b; a=a-b; printf("Values After Swapping\n "); printf("A=%d \t B=%d",a,b); getch(); } |

The numbers can then be swapped using the sum and subtraction from the sum.

**Output:**

1 2 3 4 5 6 7 |
Enter The Value for A & B 123 456 Values Before Swapping A & B A=123 B=456 Values After Swapping A=456 B=123 |