Need help to hand traching this code include using namespace
Need help to hand traching this 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;
}
Solution
In your code some errors are there i correct it and mention the program below.
#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;
}
Tracing for above mentioned code:
one=1, two=2, three =3
find(1,2,3) // function calling
Here a=1, b=2,c=3
c=a*b+2= 1*2+2 =4
temp = c = 4
if (b==0) // condition is failed so it\'s not executed
a = a+c-b = 1+4-2 = 3
b= b*temp = 2*4 = 8
now printing 3,2,8
find(2,3 ,8)// again function calling
a = 2, b=3, c=8
c = a*b+2 = 2*3+2 = 8
temp = 8
if (b==0) // condition is failed so it\'s not executed
a= a+c-b = 2+8-3 = 7
c= b*temp = 3*8 = 24
now printing 3,7,24
find(24,7,3) // again function calling
a=24, b=7, c=3
c=a*b+2 = 24*7+2 = 170
temp = 170
if (b==0) // condition is failed so it\'s not executed
a= a+c-b = 24+170-7 = 187
c= b* temp = 7*170 = 1190
now printing 1190, 7, 187
find(7,187,1190) // function calling
a = 7, b=187, c=1190
c = a * b+2 = 7*187+2 =1311
temp = 1311
if(b==0) // condition fail so it\'s not executed
a = a+c-b = 7+1311-187 = 1131
c = b* temp = 187 * 1311 = 245157
now printing 245157, 1131, 187


