Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

swap two numbers without use of third variable and also arithmetic operations

+1 vote
asked Mar 23, 2020 by Paramaguru v (130 points)

2 Answers

0 votes
answered Apr 5, 2020 by Luigi Rodorigo (280 points)

Use the XOR swap.

void swap( int* x, int* y )  {  
  if (y != x) { // important
    *x ^= *y;
    *y ^= *x;
    *x ^= *y;
  }
}
0 votes
answered Apr 5, 2020 by Prabhat Nayak (220 points)
//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);

}
commented Apr 6, 2020 by 1916114 (260 points)
its been already stated that to do not using third variable and arithmatic operations aswell
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...