Home C Language Basic C Programs Swapping of Two Numbers

Swapping of Two Numbers

Write a C Program to Swap two numbers.

#include<stdio.h>

int main()

{

   int a,b,temp;

   printf(“Enter two numbers :\n”);

   scanf(“%d %d”,&a,&b);

   printf(“Before Swapping : a = %d, b = %d\n”,a,b);

   temp=a;

   a=b;

   b=temp;

   printf(“After Swapping : a = %d, b = %d\n”,a,b);

   return 0;

}

Output :

Enter two numbers :

10536    79

Before Swapping : a = 10536, b = 79

After Swapping : a = 79, b = 10536