Skip to content

C++ Program for Exchange of Value of Two Variables Without Temporary Variable

C++ Program for Exchange of Value of Two Variables Without Temporary Variable
This code is shared by Akshay Durge


Sample Output:

Code:

/*program for exchange of value of two variables without temp variable*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int no1,no2;
void ex(int,int);  //prototype void
cout<<“enter value for a=”<<endl;
cin>>no1;
cout<<“enter value for b=”<<endl;
cin>>no2;
ex(no1,no2);   //calling the function
getch();


}
void ex(int a,int b)  //function ex with argument having two variables
{
a=a+b;
b=a-b;
a=a-b;
cout<<“new a=”<<a<<endl;;
cout<<“new b=”<<b;
}

Comment bellow for your query and feedback.. 🙂

Leave a Reply

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

error: Content is protected !!