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 :

Leave a Comment

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

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

Shopping Basket
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare
Verified by MonsterInsights