#include <stdio.h> #include <math.h> int main( void ) { double x, y; x = 2.0; y = sqrt( x ); printf( "%f の平方根は %f です\n", x, y ); return 0; } |
#include <stdio.h> #include <math.h> int main( void ) { double x, y, z; x = 15.6; y = 4.2; z = fmod( x, y ); printf( "%f を %f で割った余りは %f です\n", x, y, z ); return 0; } |
#include <stdio.h> #include <math.h> int main( void ) { double x, y, z; x = 5.0; y = 3.0; z = pow( x, y ); printf( "%f の %f 乗は %f です\n", x, y, z ); return 0; } |
#include <stdio.h> #include <math.h> int main( void ) { double x, z; int y; x = 5.0; y = 3; z = ldexp( x, y ); printf( "%f * 2^%d は %f です。 ", x, y, z ); return 0; } |
#include <stdio.h> #include <math.h> int main( void ) { double x, y; x = 15.0; y = log( x ); printf( "%f の自然対数は %f です。", x, y ); return 0; } |
#include <stdio.h> #include <math.h> int main( void ) { double x, y; x = 4.0; y = log10( x ); printf( "%f の 常用対数は %f です。\n", x, y ); return 0; } |
#include <stdio.h> #include <math.h> int main( void ) { double x, y; x = -5.6; y = fabs( x ); printf( "%f の絶対値は %f です。\n", x, y ); return 0; } |
#include <stdio.h> #include <math.h> int main( void ) { double x, y; x = 4.3; y = ceil( x ); printf( "%f を切り上げると %f になります。", x, y ); y = floor( x ); printf( "%f を切り捨てると %f になります。", x, y ); return 0; } |
#include <stdio.h> #include <math.h> #deifne PI 3.141592 int main( void ) { double x, y; x = 0.3 * pi; y = sin( x ); printf( "%f [rad] の正弦は %f です。\n", x, y ); y = cos( x ); printf( "%f [rad] の余弦は %f です。\n", x, y ); y = tan( x ); printf( "%f [rad] の正接は %f です。\n", x, y ); return 0; } |
#include <stdio.h> #include <math.h> #define PI 3.141592 int main( void ) { double x, y; x = 0.3 * PI; y = sin( x ); printf( "%f [rad] の正弦は %f です。\n", x, y ); x = asin( y ); printf( "%f の逆正弦は %f [rad] です。", y, x ); return 0; } |
#include <stdio.h> #include <math.h> #define PI 3.141592 int ] main( void ) { double x, y; x = 0.3 * PI; y = cos( x ); printf( "%f [rad] の余弦は %f です。\n", x, y ); x = acos( y ); printf( "%f の逆余弦は %f [rad] です。", y, x ); return 0; } |
#include <stdio.h> #include <math.h> #define PI 3.141592 int main( void ) { double x, y, z, c, s; x = 0.8 * pi; s = sin( x ); c = cos( x ); z = s / c; /* ← tan(x) = sin(x) / cos(x) と同じ*/ printf( "%f [rad] の正接は %f です。\n", x, z ); y = atan( z ); printf( "%f [rad] の逆正接(atan()による)は %f です\n", z, y ); y = atan2( s, c ); printf( "%f [rad] の逆正接(atan2()による)は %f です\n", z, y ); return 0; } |