C Program to swap two variables without using third variable



#include<stdio.h>
int main()
{
    int a,b;
    printf("Enter the first number\n");
    scanf("%d",&a);
    printf("Enter the second number\n");
    scanf("%d",&b);
    printf("\n before swapping a=%d b=%d\n",a,b);
    a=a+b;
    b=a-b;
    a=a-b;
    printf("\n after swapping a=%d b=%d\n",a,b);
}

Output:

C Program to swap two variables without using third variable

Comments