#include
void function(int);
int main()
{
int x;
printf(\"Enter x:\");
scanf(\"%d\", &x);
function(x);
return 0;
}
void functi
By default in UNIX, floating-point division by zero does not stop the program with an exception. Instead, it produces a result which is infinity
or NaN
. You can check that neither of these happened using isfinite
.
x = y / z; // assuming y or z is floating-point
if ( ! isfinite( x ) ) cerr << "invalid result from division" << endl;
Alternately, you can check that the divisor isn't zero:
if ( z == 0 || ! isfinite( z ) ) cerr << "invalid divisor to division" << endl;
x = y / z;