top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is divide by zero errors and how this is different then other errors?

+1 vote
269 views
What is divide by zero errors and how this is different then other errors?
posted Aug 20, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
To understand this you just need to find out why divided by zero is undefined.

To find out this please visit the following link https://www.khanacademy.org/math/algebra2/functions-and-graphs/undefined_indeterminate/v/why-dividing-by-zero-is-undefined (Just watch these 3 videos)

1 Answer

0 votes

Divide by Zero Errors

It is a common problem that at the time of dividing any number, programmers do not check if a divisor is zero and finally it creates a runtime error.

The code below fixes this by checking if the divisor is zero before dividing −

 #include <stdio.h>
 #include <stdlib.h>

main() {

   int dividend = 20;
   int divisor = 0;
   int quotient;

   if( divisor == 0){
      fprintf(stderr, "Division by zero! Exiting...\n");
      exit(-1);
   }

   quotient = dividend / divisor;
   fprintf(stderr, "Value of quotient : %d\n", quotient );

   exit(0);
}

When the above code is compiled and executed, it produces the following result −

Division by zero! Exiting...

Hope you understand the concept of Dividing with zero Error in C

answer Dec 4, 2016 by Atindra Kumar Nath
...