Here is an function to return the maximum value among three positive integers. There is an error in this function. Provide an input triple (n1,n2,n3), where n1, n2 and n3 are all positive integers, for which max3bad produces an incorrect output.
def max3bad(x,y,z): maximum = 0 if x >= y: if x >= z: maximum = x elif y >= z: maximum = y else: maximum = z return(maximum)
Answers
Answered by
1
Answer:
max3bad(2,1,4)
Explanation:
Answered by
0
Answer:
The correct code is;
int max3bad(x,y,z)
maximum = 0 ;
If (x==y==z)
{printf("all are equal ")};
If (x==y)
{printf("x and y are equal")};
If (z==y)
{printf("z and y are equal")};
If (x==z)
{printf("x and z are equal")};
if (x >y)
{
if (x > z)
{
maximum = x ;
}
}
else if (y >z)
{
maximum = y ;
}
else
maximum = z ;
}
return (maximum);
Explanation:
The bug in the code is it does not check the equality and outputs the equality sign.
inputs like 1,1,1 2,2,2 3,3,3. 'x' will be returned as a maximum in these cases whereas all are equal.
#SPJ3
25 MAY 2022.
Similar questions
Math,
2 months ago
Social Sciences,
2 months ago
English,
4 months ago
English,
4 months ago
Computer Science,
10 months ago
Computer Science,
10 months ago
Sociology,
10 months ago