Skip to main content

Swapping (Exchanging) of two numbers using third variable

#include <stdio.h>
int main()
{
  int a,b,c;
  printf("Enter two numbers ");
  scanf("%d%d", &a, &b );
  printf("\nBefore swapping, a = %d and b = %d", a, b);
  c = a;
  a = b;
  b = c;
  printf("\nAfter swapping, a=%d and b=%d", a, b);

  return 0;
}

Enter two numbers  3 4

Before swapping, a = 3 and b = 4
After swapping, a=4 and b=3 

Comments