c math.h常用函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

#define _USE_MATH_DEFINES
#include <math.h>

int (){

// double pow(double x, double y) 返回 x 的 y 次幂。

// double fabs(double x) 返回 x(浮点类型) 的绝对值。
// int abs(int x); 返回 x(整型) 的绝对值。
double x = exp(2);
double y = pow(10,2);
double z = log(exp(1));
printf("exp(2) is %f n",x);
printf("M_PI is %f n", M_PI);
printf("pow(10,2) is %f n",y);
printf("log(exp(1)) is %f n",z);
printf("log10(1000) is %f n",log10(1000));
printf("cos(M_Pi) is %f n",cos(M_PI));
printf("fabs(-10.05) is %f n",fabs(-10.05));
printf("abs(-10) is %d n",abs(-10));
}


/* output:
exp(2) is 7.389056
M_PI is 3.141593
pow(10,2) is 100.000000
log(exp(1)) is 1.000000
log10(1000) is 3.000000
cos(M_Pi) is -1.000000
fabs(-10.05) is 10.050000
abs(-10) is 10
*/