How to write a C Program to Swap two variables without using third variable in C Programming Language ?
#include<stdio.h>
int main(){
int a=5,b=10;
/* Type (a)*/
a=b+a;
b=a-b;
a=a-b;
printf("a= %d b= %d",a,b);
/* Type (a)*/
a=5;
b=10;
a=a+b-(b=a);
printf("\na= %d b= %d",a,b);
/* Type (a)*/
a=5;
b=10;
a=a^b;
b=a^b;
a=b^a;
printf("\na= %d b= %d",a,b);
/* Type (a)*/
a=5;
b=10;
a=b-~a-1;
b=a+~b+1;
a=a+~b+1;
printf("\na= %d b= %d",a,b);
/* Type (a)*/
a=5,
b=10;
a=b+a,b=a-b,a=a-b;
printf("\na= %d b= %d",a,b);
return 0;
}
You may also learn these C Program/Code :
C Program To Swap Two Numbers Without Using Third Variable
Learn More :
Swap
- C Program to Calculate Grid Size, Initialized Number onto tile, Initialize Tile Loop and If Grid is Even, Swap The Tiles Numbered 1 and 2
- C Program To Swap Two Numbers Without Using Third Variable
- C Code/Program For Swap Matrix
- C Program To Swap two Numbers Using Pointers
- C Program To Swap Two numbers Without Third Variable
- C Program Swapping numbers using call by reference
- C Function to xorSwap and addSwap in C Programming
- C Program to swap the values of two variables by using call by reference