#include<stdio.h>
void function(int);
int main()
{
int x;
printf("Enter x:");
scanf("%d", &x);
function(x);
return 0;
}
void function(int x)
{
float fx;
fx=10/x;
if(10 is divided by zero)// I dont know what to put here please help
printf("division by zero is not allowed");
else
printf("f(x) is: %.5f",fx);
}
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
With C99 you can use
fetestexcept(2)
et alia.This should do it. You need to check for division by zero before performing the division.
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
orNaN
. You can check that neither of these happened usingisfinite
.Alternately, you can check that the divisor isn't zero: