Q1: Hand trace the follwing code: #include <iostream> using namespace std; void
ID: 3940034 • Letter: Q
Question
Q1: Hand trace the follwing code:
#include <iostream>
using namespace std;
void find(int& a, int b, int& c,)
int main()
{
int one, two, three;
one = 1;
two = 2;
three = 3;
find(one, two, three);
cout << one << ", " << two << ", " << three << endl;
find(two, one, three);
cout << one << ", " << two << ", " << three << endl;
find(three, two, one);
cout << one << ", " << two << ", " << three << endl;
find(two, three, one);
cout << one << ", " << two << ", " << three << endl;
return 0;
}
void find(int& a, int b, int& c)
{
int temp;
c = a * b + 2;
temp = c;
if (b==0)
a = c / (b + 1);
a = a + c – b;
c = b * temp;
}
Explanation / Answer
#include <iostream>
using namespace std;
void find(int a, int b, int c)
int main()
{
int one, two, three;
> two = 2;
three = 3;
find(one, two, three);
cout << one << ", " << two << ", " << three << endl;
find(two, one, three);
cout << one << ", " << two << ", " << three << endl;
find(three, two, one);
cout << one << ", " << two << ", " << three << endl;
find(two, three, one);
cout << one << ", " << two << ", " << three << endl;
return 0;
}
void find(int a,int b,int c)
{
int temp;
c = a * b + 2;
temp = c;
if (b==0)
a = c / (b + 1);
a = a + c – b;
c = b * temp;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.