C program to swap two numbers without using third variable

source code


#include<stdio.h>
int main()
{
int a=5,b=10;
//process one
a=b+a;
b=a-b;
a=a-b;
printf("a= %d  b=  %d",a,b);//process two
a=5;b=10;
a=a+b-(b=a);
printf("\na= %d  b=  %d",a,b);
//process three
a=5;b=10;
a=a^b;
b=a^b;
a=b^a;
printf("\na= %d  b=  %d",a,b);
//process four
a=5;b=10;
a=b-~a-1;
b=a+~b+1;
a=a+~b+1;
printf("\na= %d  b=  %d",a,b);
//process five
a=5,b=10;
a=b+a,b=a-b,a=a-b;
printf("\na= %d  b=  %d",a,b);
return 0;
}

Comments

Popular posts from this blog

8086 STRING MANIPULATION –FIND AND REPLACE A WORD

Animated Circles In C++

C program to find out the sum of series 1 + 2 + …. + n.