swap without using third variable

[ad_1]

swapping of two numbers without using third variable in shell script
#!/bin/bash
echo "enter first number"
read a
echo "enter second number"
read b
echo "a before swapping is $a and b is $b"
#swapping
a=$((a+b))
b=$((a - b))
a=$((a-b))
echo "a after swapping is  $a and b is $b"
swap without using third variable
// SWAPPING WITHOUT USING THIRD VARIABLE
#include  
 int main()    
{    
int a=10, b=20;      
printf("Before swap a
a=a+b;//a=30 (10+20)    
b=a-b;//b=10 (30-20)    
a=a-b;//a=20 (30-10)    
printf("\nAfter swap a
return 0;  
}   

[ad_2]

Please follow and like us:
Content Protection by DMCA.com