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

if the marks obtain by a student in five different subjects are input through the keyboard write a program to find out the aggregate marks and percentage marks obtained by the student. assume that the maximum marks that can be obtained by a student in each subject is 100.

the length and breadth of a rectangle and radius of a circle are input through the keyboard. write a program to calculate the area and perimeter of the rectangle, and the area and circumference of the circle

If lengths of three sides of a tringle are input through the keyboard write a program to find the area of tringle.