Math.h
返回
math.h
#include
#include
int main(void)
{
double n;
n = sqrt(2.0);
printf("n=%f\n",n);
return 0;
}
/*
运行结果
n=1.414214
*/
#include
#include
int main(void)
{
double n;
n = pow(4.0,4.0);
printf("n: %f\n", n);
return 0;
}
/*
运行结果
n: 256.000000
*/
#include
#include
int main(void)
{
double a,b;
b = modf(123.345, &a);
printf("a = %f\n", a);
printf("b = %f\n", b);
return 0;
}
/*
运行结果
a = 123.000000
b = 0.345000
*/
#include
#include
int main(void)
{
double asin(double x);
double acos(double y);
double d;
d = asin(0.5) / 3.14159 * 180.0;
printf("d = %f\n",d);
d = acos(0.866) / 3.14159 * 180.0;
printf("d = %f\n",d);
return 0;
}
/*
运行结果
d = 30.000025
d = 30.002936
*/
// math.h, ceil
#include
#include
int main(void)
{
int intd;
intd = ceil(13.88);
printf("intd=%d\n",intd);
intd = ceil(-13.88);
printf("intd=%d\n",intd);
return 0;
}
/*
运行结果
intd=14
intd=-13
*/
math.h exp,fabs,floor fmod
#include
#include
int main(void)
{
double d;
d = exp(1.0);
printf("e=%f\n",d);
d = exp(2.0);
printf("e=%f\n",d);
d = exp(3.0);
printf("e=%f\n",d);
d = exp(4);
printf("e=%f\n",d);
d = fabs(-888.8);
printf("d=%f\n",d);
return 0;
}
/*
运行结果1(printf错误)
printf("e=%d\n",d);
e=-1961601175
e=-1194009170
运行结果2
e=2.718282
e=7.389056
e=20.085537
e=54.598150
d=888.800000
*/
#include
#include
int main(void)
{
int d;
double d1;
d = floor(8888.88);
printf("d=%d\n",d);
d = floor(-8888.88);
printf("d=%d\n",d);
d1 = fmod(100,3);
printf("d1=%f\n",d1);
return 0;
}
/*
运行结果
d=8888
d=-8889
d1=1.000000
*/
math.h,atan
#include
#include
int main(void)
{
double atan(double x);
double atan2(double y, double x);
double d;
d = atan(0.577) / 3.14159 * 180.0;
printf("d = %f\n",d);
d = atan2(0.577, 1.0 ) / 3.14159 * 180.0;
printf("d = %f\n",d);
return 0;
}
/*
运行结果
d = 29.984971
d = 29.984971
*/
指数分解,math.h frexp
#include
#include
int main(void)
{
double x;
int p;
x = frexp(20.0, &p);
printf("x=%f p=%i\n",x,p);
return 0;
}
/*
运行结果
x=0.625000 p=5
0.625*(2**5) = 20.0
*/
#include
#include
int main(void)
{
double d;
d = log(2.718282);
printf("d=%f\n",d);
d = log10(1000);
printf("d=%f\n",d);
return 0;
}
/*
运行结果
d=1.000000
d=3.000000
*/
返回