EmbLogic's Blog

Swap / Interchange two variables without using Third Variable

#include

int main() {
int num1, num2;

printf(“\nEnter First Number : “);
scanf(“%d”, &num1);

printf(“\nEnter Second Number : “);
scanf(“%d”, &num2);

num1 = num1 ^ num2;
num2 = num1 ^ num2;
num1 = num1 ^ num2;

printf(“\n Numbers after Exchange : “);
printf(“\n Num1 = %d and Num2 = %d”, num1, num2);

return(0);
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>