C Program to swap two numbers in a single line


In this program, You will learn how to swap two numbers in a single line in C.


Before swap: 10 20

After swap: 20 10


Example: How to swap two numbers in a single line in C

Run it Now
#include<stdio.h>

int main() {

   int x, y;

   printf("Enter Two Numbers :");
   scanf("%d%d", &x, &y);

   x ^= y ^= x ^= y;

   printf("\nAfter Swap x is :%d", x);
   printf("\nAfter Swap y is :%d", y);

   return 0;
}

Output:

Enter Two Numbers :12 13
After Swap x is :13
After Swap y is :12