Swapping of two No.s

Akhilesh Sinha


Using temp variable

int a,b,temp;

temp = a;

a = b ;

b = temp;


Without using any temp variable

int a,b;

a = a+b;

b = a-b;

a = a-b;


Swap in just one statement !!
b=a+b-(a=b)

or

a=a+b-(b=a)

Like what you read? Give Akhilesh Sinha a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.