/* * mathfncs.c - Uses math.h functions * fabs - return absolute value of xx * floor - returns largest integer not greater than xx * pow - return xx to the yy power * sqrt - returns square root of xx * ceil - returns lowest integer not smaller than xx * fmod - returns floating point remainder of xx/yy */ #include #include // This line is ESSENCIAL int main(void) { double xx=2.7; double yy=-6.3; double aa=10.0; double bb=2.0; double nn=16.0; double ce=9.1; double fma=3.5; double fmb=3.4; printf("The absolute value of %.2f is %.2f\n", xx, fabs(xx) ); printf("The absolute value of %.2f is %.2f\n", yy, fabs(yy) ); printf("The absolute value of %.2f is %.2f\n", -xx, fabs(-xx) ); printf("The largest float-integer number not greater"); printf("than %.2f is %.2f\n", xx, floor(xx) ); printf("The largest float-integer number not greater"); printf("than %.2f is %.2f\n", -xx, floor(-xx) ); printf("The %.2f to the power of %.2f is %.2f\n", aa, bb, pow(aa,bb) ); printf("The %.2f to the power of %.2f is %.2f\n", aa, -bb, pow(aa,-bb) ); printf("The square root of %.2f is %.2f\n", nn, sqrt(nn) ); printf("ceil(x) returns the smallest integer not less than xx:\n"); printf("ceil of 9.1 is: %.2f\n\n", ceil(ce) ); printf("fmod(x,y) returns floating point remainder, same sign as xx:\n"); printf("fmod of (3.5, 3.4) is: %.2f\n\n", fmod(fma, fmb) ); return 0; }