Question:
#include<iostream>
using namespace std;
void swap_by_ref(int &,int &,int &); //Swaps the values of x and z "permanently".
int main()
{
int x,y,z;
cout<<"Enter 3 numbers followed by spaces or enter: "; cin>>x>>y>>z;
swap_by_ref(x,y,z);
cout<<"x = "<<x<<" \t y = "<<y<<" \t z = "<<z<<endl;
return 0;
}
void swap_by_ref(int &x, int &y, int &z)
{
//Logic behind Swaping
int temporary_variable_1 = x;
x = z;
int temporary_variable_2 = y;
y = temporary_variable_1;
z = temporary_variable_2;
}
Write a function that receives as input three integer arguments and then circularly shift their values to right. (The change in variables must be permanent) Example:
If x=5, y=8, z=10 then after circular shift y=5, z=8, and x=10.
#include<iostream>
using namespace std;
void swap_by_ref(int &,int &,int &); //Swaps the values of x and z "permanently".
int main()
{
int x,y,z;
cout<<"Enter 3 numbers followed by spaces or enter: "; cin>>x>>y>>z;
swap_by_ref(x,y,z);
cout<<"x = "<<x<<" \t y = "<<y<<" \t z = "<<z<<endl;
return 0;
}
void swap_by_ref(int &x, int &y, int &z)
{
//Logic behind Swaping
int temporary_variable_1 = x;
x = z;
int temporary_variable_2 = y;
y = temporary_variable_1;
z = temporary_variable_2;
}
No comments:
Post a Comment