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

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

To understand this you just need to find out why divided by zero is undefined.

### 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