Use the XOR swap.

void swap( int* x, int* y ) { if (y != x) { // important *x ^= *y; *y ^= *x; *x ^= *y; } }

0 votes

Use the XOR swap.

void swap( int* x, int* y ) { if (y != x) { // important *x ^= *y; *y ^= *x; *x ^= *y; } }

0 votes

//for swap two number in c

#include<stdio.h>

void main()

{

int a,b;

printf("enter two number which are storing at a and b");

scanf("%d%d",&a,&b);

a=a+b;

b=a-b;

a=a-b;

printf(" a and b is %d, %d",a,b);

}

#include<stdio.h>

void main()

{

int a,b;

printf("enter two number which are storing at a and b");

scanf("%d%d",&a,&b);

a=a+b;

b=a-b;

a=a-b;

printf(" a and b is %d, %d",a,b);

}

commented
3 days ago
by
(260 points)

its been already stated that to do not using third variable and arithmatic operations aswell

...