/* Author : Michael Robinson Program : mathFunctions.c Purpose : math functions samples Updated : 06-29-2014 */ #include #include #include #include #define PI 3.14159265 void VariousMathFunctions() { printf( "\nVarious Math Functions\n" ); printf( "----------------------\n" ); printf("the abs of %6d is = %6d\n", -20, abs( -20 ) ); printf("the fabs of %6.2f is = %6.2f\n", -12.1, fabs( -12.1 ) ); printf("the ceil of %6.2f is = %6.2f\n", 12.1, ceil( 12.1 ) ); printf("the floor of %6.2f is = %6.2f\n", 20.9, floor( 20.9 ) ); printf("the fmod of %6.2d is = %6.2f\n", 120, fmod( 120, 5 ) ); printf("the trunc of %6.2f is = %6.2f\n", -20.02, trunc( -20.02 ) ); } void ExponentialLogarithmicPowerFunctions() { printf( "\nExponential, Logarithmic, and Power Functions\n" ); printf( "---------------------------------------\n" ); printf("the exp of %d is = %f\n", 4, exp( 4 ) ); printf("the ldexp of %d is = %f\n", 4, ldexp( 4,2 ) ); printf("the log2 of %d is = %2.0f\n", 1000000, log2( 1000000 ) ); printf("the log10 of %d is = %2.0f\n", 1000000, log10( 1000000 ) ); printf("the modf of %.5lf is = \n", 8.12345 ); double x, fractpart, intpart; fractpart = modf(8.12345, &intpart); printf( " Integral part = %.5lf\n", intpart ); printf( " Fraction Part = %.5lf \n", modf( 8.12345, &intpart ) ); printf("the pow of %d is = %6.2f\n", 10, pow( 10,2 ) ); printf("the sqrt of %d is = %6.2f\n", 36, sqrt( 36 ) ); } void trigonometicFunctions() { printf( "\nTrigonometic Functions" ); printf( "\n----------------------\n" ); printf("the cos of %d is = %f\n", 16, cos( 16 ) ); printf("The acos of %.1f is = %lf degrees\n", 0.9, acos( 0.9 ) * (180.0 / PI) ); printf("the cosh of %d is = %f\n", 16, cosh( 16 ) ); printf("the sin of %d is = %f\n", 16, sin( 16 ) ); printf("the sinh of %d is = %f\n", 16, sinh( 16 ) ); printf("The asin of %.1f is = %lf degrees\n", 0.9, asin( 0.9 ) * (180.0 / PI) ); printf("the tan of %d is = %f\n", 4, tan( 4 ) ); printf("the atan of %d is = %f\n", 4, atan( 4 ) ); printf("the atan2 of %d is = %f\n", 4, atan2( 4,2 ) ); } int main() { trigonometicFunctions(); ExponentialLogarithmicPowerFunctions(); VariousMathFunctions(); exit(0); //needs #include }