#16: What is the output of the following program AND WHY? #include <iostream> us
ID: 3631158 • Letter: #
Question
#16: What is the output of the following program AND WHY?#include <iostream>
using namespace std;
int mystery (int x, int y, int z);
int main ()
{
cout << mystery (7, 8, 3) << endl;
cout << mystery (10, 5, 30) << endl;
cout << mystery (9, 12, 11) << endl;
cout << mystery (5, 5, 8) << endl;
cout << mystery (10, 10, 10) << endl;
return 0;
}
int mystery (int x, int y, int z)
{
if (x <= y && x <= z)
return (y + z -x);
else if (y <= z && y <= x)
return (z + x - y);
else
return (x + y - z);
}
Explanation / Answer
please rate - thanks
#include <iostream>
using namespace std;
int mystery (int x, int y, int z);
int main ()
{ //each call prints what is returned
cout << mystery (7, 8, 3) << endl;
cout << mystery (10, 5, 30) << endl;
cout << mystery (9, 12, 11) << endl;
cout << mystery (5, 5, 8) << endl;
cout << mystery (10, 10, 10) << endl;
return 0;
}
int mystery (int x, int y, int z) call 1 call 2 call 3 call 4 call 5
{ x y z x y z x y z x y z x y z
7 8 3 10 5 30 9 12 11 5 5 8 10 10 10
if (x <= y && x <= z) false false true true true
return (y + z -x); return 14 return 8 return 10
else if (y <= z && y <= x) false true
return (z + x - y); return 35
else
return (x + y - z); return 12
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.