Swap using third variable - C Program

C program to read two numbers and exchange their values using third variable.

Solution:

In this program, swap or exchange the values of variable with the help of third variable.

#include <stdio.h>
int main()
{
      int a,b,t;
      printf("\tEnter Two Numbers\n");
      printf("----------------------------\n");
      printf("Enter First Number  : ");
      scanf("%d", &a);
      printf("\nEnter Second Number : ");
      scanf("%d",&b);
      printf("----------------------------\n");
      printf("\nBefore Exchange a= %d b=%d\n",a,b);
      /*With using third variable*/
      t=a;
      a=b;
      b=t;
      printf("\nAfter Exchange  a=%d  b=%d",a,b);
      return 0;
}


Output:

swap two no