To perform Swapping operation with using third variable.

Write a Program to perform Swapping operation with using third variable.


Source Code:

#include<stdio.h>
#include<conio.h>
void main()
{
	int a,b,c;
	clrscr();
	printf("Enter the value of a:");
	scanf("%d",&a);
	printf("Enter the value of b:");
	scanf("%d",&b);

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


	c=a+b;
	b=c-b;
	a=c-b;
	
	printf(“After Swapping: \n”);
	printf("Value of a is=%d \n", a);
	printf("Value of b is=%d \n", b);

	getch();
}


Output:

Enter the value of a: 10
Enter the value of b: 20

Before Swapping:
Value of a is = 10
Value of b is = 20

After Swapping:
Value of a is = 20 
Value of b is = 10

Leave a Reply

Your email address will not be published. Required fields are marked *