Hi,
Two ways to avoid the error "Divided by Zero".
int a,b,c;
a = 2;
b = 0;
if(b)
c = a / b;
else
print "Cannot divide by zero"
//Output is "Cannot divide by zero" because "b" is zero so else statement will run.
(OR)
c = a / minOne(b);
//Output is C = 2, reason given below.
Function minOne() returns non zero values. If "b" is zero then it returns one.
Thank you,
No comments:
Post a Comment