Write a program using reference variables a argument to swap the value of a pair of a integers of C++.

 Write a program using reference variables a argument to swap the value of a pair of a integers

 #include<iostream>

using namespace std;

void swap(int&x,int&y)

{
int temp;

temp =x;

x=y;

y=temp;

}

int main(){

int a,b;

cout<<"Enter the value of a";

cin>>a;

cout<<"Enter the value of b";

cin>>b;

cout<<"\n"<<"Before swapping:";

cout<<" a="<<a<<"and b = "<<b;

swap(a,b);

 cout<<"\n"<<"After swapping:"; 

cout<<" a="<<a<<"and b = "<<b;

}

or 

👇👇👇👇👇👇👇👇👇👇👇👇👇

 #include<iostream>
using namespace std;
void swap(int&x,int&y)
{
int temp;
temp =x;
x=y;
y=temp;
}
int main(){
int a,b;
cout<<"Enter the value of a:";
cin>>a;
cout<<"Enter the value of b:";
cin>>b;
cout<<"\n"<<"Before swapping:";
cout<<" a="<<a<<" and b = "<<b;
swap(a,b);
 cout<<"\n"<<"After swapping:";
cout<<" a="<<a<<" and b = "<<b;
}

output--


Enter the value of a : 4

Enter the value of b : 6

before swapping a=4 and b=6

after swapping  a=6 and b=4

 





 



Comments

Popular posts from this blog

class with array in c++ (memory allocatin & using array in classes)

constructor with default arguments

constructor overloading in c++ programming