Respuesta :
Answer:
a. cout<<hidden(15,10)<<endl;
output = 5
b. cout << compute(3, 9) << endl;
output=3
c. cout << hidden(30, 20) << " " << compute(10, hidden(30, 20)) << endl;
output = 10
d. x = 2; y = 8; cout << compute(y, x) << endl;
output= 8
Explanation:
solution a:
num1= 15;
num2= 10;
according to condition 1, num1 is not greater than 20. In condition 2, num2 is also not greater than 20.
so,
the solution is
return num1 - num2 = 15 - 10 = 5
So the output for the above function is 5.
solution b:
as in function there are two integer type variables named as one and two. values of variables in given part are:
one = 3
two = 9
secret = one = 3
for (int i= one + 1 = 3+1 = 4; i<=9%2=1; i++ )
9%2 mean find the remainder for 9 dividing by 2 that is 1.
// there 4 is not less than equal to 1 so loop condition will be false and loop will terminate. statement in loop will not be executed.
So the answer will be return from function compute is
return secret ;
secret = 3;
so answer return from the function is 3.
solution c:
As variables in first function are num1 and num2. the values given in part c are:
num1 = 30;
num2= 20;
According to first condition num1=30>20, So,
num1= num2/10
so the solution is
num1 = 20/10 = 2
now
num1=2
now the value return from function Hidden is,
return num1*num2 = 2* 20 = 40
Now use the value return from function hidden in function compute as
compute(10, hidden(30, 20))
as the value return from hidden(30, 20) = 40
so, compute function becomes
compute(10, 40)
Now variable in compute function are named as one and two, so the values are
one= 10;
two = 40;
as
secret = one
so
secret = 10;
for (int i= one + 1 = 10+1 = 11; i<=40%2=0; i++ )
40%2 mean find the remainder for 40 dividing by 2 that is 0.
// there 11 is not less than equal to 0 so loop condition will be false and loop will terminate. statement in loop will not be executed.
So the answer will be return from function compute is
return secret ;
secret = 10;
so answer return from the function is 10.
solution d:
Now variable in compute function are named as one and two, so the values are
one = y = 8
two = x = 2
There
Secret = one = 8;
So
for (int i= one + 1 = 8+1 = 9; i<=2%2=0; i++ )
2%2 mean find the remainder for 2 dividing by 2 that is 0.
// there 9 is not less than equal to 0 so loop condition will be false and loop will terminate. statement in loop will not be executed.
So the answer will be return from function compute is
return secret ;
secret = 8;
so answer return from the function is 8.