Program to show swap of two no’s without using third variable

Program to show swap of two no’s without using third variable
step1:- Addition of a and b store in a(For Example a=5,b=6),Now a=5+6
step2:- b=a-b  (b=11-6)  Now b is 5;
step3:- a=a-b  (a=11-5)

#include<stdio.h>

void main()
{
int a,b;

printf("enter value for a & b: \n");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("After swapping the value of a : %d\n b: %d\n",a,b);
}

Related Posts