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)

paper of size A0 has dimensions 1189 mmx 841 mm .Each subsequent size A(n) is defined as A(n-1) cut in half parallel to its shorter sides .Thus paper of size A1 would have dimensions 841 mm X 594 mm .Write a program to calculate the print paper sizes A0,A1,A2,.........A8.

constructor with default arguments