DIVCHK Editorial

PROBLEM LINK:

Practice
Contest

Author: Baban Gain
Editorialist: Baban Gain

DIFFICULTY:

CAKEWALK

PREREQUISITES:

High School Mathematics

PROBLEM:

Your little brother has made a program to divide two numbers, A/B that only supports integer output.
As he haven’t handled any exceptions, the program will crash if any error occurs.
For given two numbers, predict if his program will be safe after execution.

EXPLANATION:

A/B result will be integer if and only if A % B equals 0 (zero) where % signifies modulo operation.
However, if B=0, then the your brother’s program should crash beacuse A/0 is not integer.
If you try to calculate A%0, Due to “Division by zero error” your program would also crash along with your brother’s one. :slight_smile:
So,
if B equals 0, then crash
else if A%B equals 0 then safe
else crash

AUTHOR’S SOLUTIONS:

Click for Python
Click for C++
Click for Java