C++ Program for Exchange of Value of Two Variables Without Temporary Variable
Sample Output:
Code:
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.. :)#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;
}
No comments:
Post a Comment