Two non-negative integers x and y are equal if either: Both are 0, or x-1 and y-1 are equal Write a boolean-method named equals that recursively determines whether its two int parameters are equal and returns true if they are and false otherwise.

Respuesta :

Limosa

Answer:

Following are the code which is mention below.

bool equals (int x, int y)  // method equals

{

if( (x<0) || (y<0) )  // check number if it is less then 0

return false;  // return false

if( (x==0) && (y==0) )  // check condition if number is equal to 0

return true;  // return true

return equals(x-1, y-1);  

}

Explanation:

  • Here we declared a function "equals" of type bool which means it either return "true" or "false".
  • Inside the function equals we check the condition which are mention above

                   1.   if x and y both are less then  0 then it returns "false".

                   2.  if x and y both are equal to 0 then it returns "true"

                   3.   Otherwise it return x-1 and y-1.