C++ Program – Swap two numbers without using a 3rd variable using function with arguments.
/* 15. Write a program to swap two numbers without using third variable
using function with argument*/
#include<iostream.h>
#include<conio.h>
void swap(int*,int*);
void main()
{
clrscr();
int a,b;
cout<<"Enter value for a="<<endl;
cin>>a;
cout<<"Enter value for b="<<endl;
cin>>b;
swap(&a,&b);
cout<<"After swapping:"<<endl<<"a="<<a<<" "<<"b="<<b<<endl;
getch();
}
void swap(int *a,int *b)
{
*a=*a+*b;
*b=*a-*b;
*a=*a-*b;
}