Section: For each of the given program segments, determine if there is an error
ID: 3830394 • Letter: S
Question
Section: For each of the given program segments, determine if there is an error in the code. If there is an error, specify whether it is a logic or compilation error, circle the error in the program, and write the corrected code in the space provided after each problem. If the code d not contain an error, write "no error." [Note: It is possible a program segment may contain multiple errors.] 37. The following program segment defines function maximum, which returns the largest of three integers I int maximum int x, int y, int z): 3 int max x 5 if y max) max yi B if z max. max X 10 return max 12 end function maximum Your answer: 38. The following program segment should output five random numbers in the range from 1 to 6, inclusive: for int i 1; i ca 5: i++) 2 cout setw( 10 1 srando x 6 your o 2012 Pearson Education, Inc.. Upper Saddle River, NJ, AN Rights Reserved.Explanation / Answer
In this function we are trying to return maximum number among x, y and z. Please find the comment inline. Logically given program is incorrect. Following is the corrected program.
int maximun(int x, int y, int z)
{
int max = x;
if(y>max)
max = y;
if(z>max)
max = z; // It is incorrectly given as
return max;
}