Learning by doing: Reading books and trying to understand the (code) examples
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

50 lines
713 B

#include <stdio.h>
#include <math.h>
#include <fenv.h>
double cubeNumber(double number);
int main (void) {
double number;
double cube_number;
int error = 0;
printf("Give a number: ");
if (scanf("%lf", &number) != 1 || isnan(number)) {
printf("Not a number!\n");
error = 1;
} else {
cube_number = cubeNumber(number);
if (cube_number != NAN) {
printf("%lf\n", cube_number);
} else {
printf("Floating point exception occured!\n");
error = 1;
}
}
return error;
}
double cubeNumber (double number) {
double i;
feclearexcept(FE_ALL_EXCEPT);
i = pow(number, 3);
if (fetestexcept(FE_ALL_EXCEPT) == 0) {
i = NAN;
}
return i;
}