Learn Programming C | C++ | Java | Android | Tips and Tricks

C Program to show swap of two no’s without using third variable

Program to show swap of two no’s without using third variable

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("\nEnter value for num1 & num2 : ");
scanf("%d %d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("\nAfter swapping value of a : %d",a);
printf("\nAfter swapping value of b : %d",b);
getch();
}

Output :

Enter value for num1 & num2 : 10 20
After swapping value of a : 20
After swapping value of b : 10

About The Author

Pritesh Taral working in well known MNC as Java Developer.He is tech blogger writing articles on multiple technologies such as ExtJs | Java | Web Development | Desktop Programming etc.Follow Him - Facebook | Tweeter | Google+