Google News
logo
C-Language - Interview Questions
How to write a program in C for swapping two numbers without the use of the third variable?
#include <stdio.h>
int main()
{
   int x, y; 
   printf(“Input two integers (x & y) to swap\n”);
   scanf(“%d%d”, &x, &y);
   x = x + y;
   y = x – y;
   x = x – y;
   printf(“x = %d\ny = %d\n”,x,y);
   return 0;
}
Advertisement