Program to swap two numbers without using third variable

A simple program to swap two numbers without using the third variable. You have to use some formulas or basic concepts.

#include<stdio.h>
#include<conio.h>

void main()
{
int a,b;
clrscr();

printf(“enter any number”);  
scanf(“%d”,&a);

printf(“enter any number”); 
scanf(“%d”,&b);

a=a+b;   
b=a-b;    
a=a-b;

printf(“%d\n”,a);
printf(“%d\n”,b);

getch();
}

Output:

swap two number without using third variable

 

 

Leave a Reply