Given two optimistic integers Num1 and Num2, the duty is to search out the rest when Num1 is split by Num2.
Examples:
Enter: Num1 = 11, Num2 = 3
Output: 2
Rationalization: 3) 11 (3
– 9
———
2 -> The rest
———-Enter: Num1 = 15, Num2 = 3
Output: 0
Method: The issue will be solved through the use of the modulus operator.
- Modulus operator returns the rest, if we write a % b, it returns the rest when a is split by b the place b != 0. If b = 0, then it provides Runtime Error,
- Math error in C++, [Math error: Attempted to divide by Zero]
- ZeroDivisionError in Python, [ZeroDivisionError: integer division or modulo by zero]
- ArithmeticException in Java [ArithmeticException: / by zero]
Beneath is the implementation of the above strategy:
C++
|
Time Complexity: O(1)
Auxiliary Area: O(1)