C Program to Swap Two Numbers without Third Variable


In C programming, you can swap the values of two variables without using a third variable by using arithmetic operations. The key idea is to use addition and subtraction (or multiplication and division) to perform the swap. Here’s an example:

Program :

#include<stdio.h>
#include<conio.h>
main()
{
int a,b;
printf(“Enter the First Number : “);
scanf(“%d”,&a);
printf(“Enter the Second Number : “);
scanf(“%d”,&b);
a=a+b;
b=a-b;
a=a-b;
printf(“\nAfter Swapping…\nFirst Number : %d”,a);
printf(“\nSecond Number : %d”,b);
}

Output :

19 thoughts on “C Program to Swap Two Numbers without Third Variable”

Leave a Comment

Your email address will not be published.

Shopping Basket
Verified by MonsterInsights