5. Compound Operators
Compound operators are combination of arithmetic
and assignment operator. Compound operators are also called as short cut operators.
These will work same as arithmetic operator.
Those are
+=
-=
*=
/=
%=
Ex 1: n1=10 n2=5
n1=n1+n2 (n1+=n2)
n1=10+5 10+=5
n1=15 n1=15
Ex 1: n1=10 n2=5
n1=n1+n2 (n1+=n2)
n1=10+5 10+=5
n1=15 n1=15
Ex 2: n1=10 n2=5
n1=n1-n2 (n1-=n2)
n1=10-5 10-=5
n1=5 n1=5
Ex 3: n1=10 n2=5
n1=n1*n2 (n1*=n2)
n1=10*5 10*=5
n1=50 n1=50
Ex 4: n1=10 n2=5
n1=n1/n2 (n1/=n2)
n1=10/5 10/=5
n1=2 n1=2
Ex 5: n1=10 n2=5
n1=n1%n2 (n1%=n2)
n1=10%5 10%=5
n1=0 n1=0
Write a program to swap two numbers without
using temporary variable (or) without using third variable.
output


No comments:
Post a Comment