To perform Swapping operation without using third variable.

Write a Program to perform Swapping operation without 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);

	a=a+b;
	b=a-b;
	a=a-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 *