Examine the code below What does the following function do I
Examine the code below. What does the following function do? Int mystery(int x, int y, int z) {int temp; temp=x; if (y > temp) {temp = y;} if (z > temp) {temp = z;} return temp;}
Solution
// function mystery takes three integer parameters
int mystery(int x, int y, int z){
int temp;
temp = x; // storing x value (or initializing temp with x value)
if(y > temp){ // if y value is greater than x then storing y value in temp
temp = y;
}
if(z > temp){ // if z value is greater than temp, storing z value in temp
temp = z;
}
return temp; // returning temp value
}
Explanation:
So, overall we are storing maximum value in temp among x, y and z
