Swap Two Numbers

//interchanging the value of two variable
#include<stdio.h>
void main()
{
int a,b,t;
printf(“enter the value of a and b\n”);
scanf(“%d%d”,&a,&b);
printf(“Before Swap:\n a=%d,\tb=%d”,a,b);
t=a;
a=b;
b=t;
printf(“\nAfter Swap:\n a=%d,\tb=%d”,a,b);
}

OUTPUT

Here a Temporary variable is used to interchange the value of variables. Initially the value of a is stored in temporary variable t. Then, the value of b is override the value of a and then finally the value of b is overridden by temporary variable value. Hence, the value is Swapped.

Leave a Reply

Your email address will not be published.