c <math.h>

来源:互联网 发布:python 做个静态网页 编辑:程序博客网 时间:2024/05/22 01:47

MATH.H
1. abs
2. fabs
3. cabs
4. ceil
5. sin
6. cos
7. tan
8. asin
9. acos
10. atan
11. atan2
12. sinh
13. cosh
14. tanh
15. exp
16. floor
17. fmod
18. frexp
19. log
20. log10
21. modf
22. pow
23. sqrt
24. hypot
25. poly
26. matherr
27. ldexp

函数名称: abs
函数原型: int abs(int x);
函数功能求整数x的绝对值
函数返回计算结果
参数说明:
所属文件: <math.h>,<stdlib.h>
使用范例:
#include <stdio.h>
#include <math.h>
int main()
{
int number=-1234;
printf("number: %d absolute value: %d",number,abs(number));
return 0;
}
________________________________________
函数名称: fabs
函数原型double fabs(double x);
函数功能x的绝对值.
函数返回计算结果
参数说明:
所属文件: <math.h>
使用范例:
#include <stdio.h>
#include <math.h>
int main()
{
float number=-1234.0;
printf("number: %f absolute value: %f",number,fabs(number));
return 0;
}
________________________________________
函数名称: cabs
函数原型: double cabs(struct complex znum)
函数功能求复数的绝对值
函数返回复数的绝对值
参数说明: zuum为用结构struct complex表示的复数,定义如下:
struct complex{
double m;
double n;
}
所属文件: <math.h>

#include <stdio.h>
#include <math.h>
int main()
{
struct complex z;
double val;
z.x=2.0;
z.y=1.0;
val=cabs(z);
printf("The absolute value of %.2lfi %.2lfj is %.2lf",z.x,z.y,val);
return 0;
}
________________________________________
函数名称: ceil
函数原型: double ceil(double num)
函数功能得到不小于num的最小整数
函数返回用双精度表示的最小整数
参数说明: num-实数
所属文件: <math.h>

#include <math.h>
#include <stdio.h>
int main()
{
double number=123.54;
double down,up;
down=floor(number);
up=ceil(number);
printf("original number %5.2lf",number);
printf("number rounded down %5.2lf",down);
printf("number rounded up %5.2lf",up);
return 0;
}
________________________________________
函数名称: sin
函数原型: double sin(double x);
函数功能计算sinx的值.正弦函数
函数返回计算结果
参数说明单位为弧度
所属文件: <math.h>
使用范例:
#include <stdio.h>
#include <math.h>
int main()
{
double result,x=0.5;
result=sin(x);
printf("The sin() of %lf is %lf",x,result);
return 0;
}
________________________________________
函数名称: cos
函数原型: double cos(double x);
函数功能计算cos(x)的值.余弦函数.
函数返回计算结果
参数说明: x的单位为弧度
所属文件: <math.h>
使用范例:
#include <stdio.h>
#include <math.h>
int main()
{
double result;
double x=0.5;
result=cos(x);
printf("The cosine of %lf is %lf",x,result);
return 0;
}
________________________________________
函数名称: tan
函数原型: double tan(double x);
函数功能计算tan(x)的值,即计算角度x的正切数值
函数返回计算结果
参数说明: x>=0单位为弧度
所属文件: <math.h>
使用范例:
#include <stdio.h>
#include <math.h>
int main()
{
double result,x;
x=0.5;
result=tan(x);
printf("The tan of %lf is %lf",x,result);
return 0;
}
________________________________________
函数名称: asin
函数原型: double asin(double x);
函数功能计算sin^-1(x)的值.反正弦值函数
函数返回计算结果
参数说明: x应在 -1 到 范围内.单位为弧度
所属文件: <math.h>
使用范例:
#include <stdio.h>
#include <math.h>
int main()
{
double result;
double x=0.5;
result=asin(x);
printf("The arc sin of %lf is %lf",x,result);
return 0;
}
________________________________________
函数名称: acos
函数原型: double acos(double x);
函数功能计算cos^-1(x)的值,反余弦函数
函数返回计算结果
参数说明: x应在-11范围内.切记单位为弧度
所属文件: <math.h>
使用范例:
#include <stdio.h>
#include <math.h>
int main()
{
double result;
double x=0.5;
result=acos(x);
printf("The arc cosine of %lf is %lf",x,result);
return 0;
}
________________________________________
函数名称: atan
函数原型: double atan(double x);
函数功能计算tan^-1(x)的值.
函数返回计算结果
参数说明单位为弧度
所属文件: <math.h>
使用范例:
#include <stdio.h>
#include <math.h>
int main()
{
double result;
double x=0.5;
result=atan(x);
printf("The arc tangent of %lf is %lf",x,result);
return 0;
}
________________________________________
函数名称: atan2
函数原型: double atan2(double x,double y);
函数功能计算tan^-1/(x/y)的值.x/y的反正切值.
函数返回计算结果
参数说明单位为弧度
所属文件: <math.h>
使用范例:
#include <stdio.h>
#include <math.h>
int main()
{
double result;
double x=90.0,y=45.0;
result=atan2(y,x);
printf("The arc tangent ratio of %lf is %lf",(y/x),result);
return 0;
}
________________________________________
函数名称: sinh
函数原型: double sinh(double x);
函数功能计算x的双曲正弦函数sinh(x)的值.
函数返回计算结果
参数说明单位为弧度
所属文件: <math.h>
使用范例:
#include <stdio.h>
#include <math.h>
int main()
{
double result,x=0.5;
result=sinh(x);
printf("The hyperbolic sin() of %lf is %lf",x,result);
return 0;
}
________________________________________
函数名称: cosh
函数原型: double cosh(double x);
函数功能计算x的双曲余弦cosh(x)的值.
函数返回计算结果
参数说明:
所属文件: <math.h>
使用范例:
#include <stdio.h>
#include <math.h>
int main()
{
double result;
double x=0.5;
result=cosh(x);
printf("The hyperboic cosine of %lf is %lf",x,result);
return 0;
}
________________________________________
函数名称: tanh
函数原型: double tanh(double x);
函数功能计算x的双曲正切函数tanh(x)的值.
函数返回计算结果
参数说明: x>=0
所属文件: <math.h>
使用范例:
#include <stdio.h>
#include <math.h>
int main()
{
double result,x;
x=0.5;
result=tanh(x);
printf("The hyperbolic tangent of %lf is %lf",x,result);
return 0;
}
________________________________________
函数名称: exp
函数原型: double exp(double x);
函数功能ex次幂
函数返回计算结果.幂的值
参数说明: x-指数
所属文件: <math.h>
使用范例:
#include <stdio.h>
#include <math.h>
int main()
{
double result;
double x=4.0;
result=exp(x);
printf("'e' raised to the power of %lf(e^%lf)=%lf",x,x,result);
return 0;
}
________________________________________
函数名称: floor
函数原型: double floor(double x);
函数功能求出不大于x的最大整数.
函数返回该整数的双精度实数
参数说明:
所属文件: <math.h>
使用范例:
#include <stdio.h>
#include <math.h>
int main()
{
double number=123.54;
double down,up;
down=floor(number);
up=ceil(number);
printf("original number %10.2lf",number);
printf("number rounded down %10.2lf",down);
printf("number rounded up %10.2lf",up);
return 0;
}
________________________________________
函数名称: fmod
函数原型: double fmod(double x,double y);
函数功能求整数x/y的余数
函数返回返回余数的双精度数.x/y的余数值.
参数说明:
所属文件: <math.h>
使用范例:
#include <stdio.h>
#include <math.h>
int main()
{
double x=5.0,y=2.0;
double result;
result=fmod(x,y);
printf("The remainder of (%lf/%lf) is %lf",x,y,result);
return 0;
}
________________________________________
函数名称: frexp
函数原型: double frexp(double val,int *eptr);
函数功能把双精度数val分解为数字部分(尾数)x和以2为底的指数n,val=x*2^n,n存放在eptr指向的变量中.
函数返回返回数字部分x,0.5<=xx<1
参数说明: val-待分解的数
所属文件: <math.h>
使用范例:
#include <math.h>
#include <stdio.h>
int main()
{
double mantissa,number;
int exponent;
number=8.0;
mantissa=frexp(number,&exponent);
printf("The number %lf is",number);
printf("%lf times two to the",mantissa);
printf("power of %d",exponent);
return 0;
}
________________________________________
函数名称: log
函数原型: double log(double x);
函数功能logeX(e指的是以e为底),即计算x的自然对数(ln X)
函数返回计算结果
参数说明:
所属文件: <math.h>
使用范例:
#include <math.h>
#include <stdio.h>
int main()
{
double result;
double x=8.6872;
result=log(x);
printf("The natural log of %lf is %lf",x,result);
return 0;
}
________________________________________
函数名称: log10
函数原型: double log10(double x);
函数功能log10x(10指的是以10为底).计算x的常用对数
函数返回计算结果
参数说明:
所属文件: <math.h>
使用范例:
#include <math.h>
#include <stdio.h>
int main()
{
double result;
double x=800.6872;
result=log10(x);
printf("The common log of %lf is %lf",x,result);
return 0;
}
________________________________________
函数名称: modf
函数原型: double modf(double val,double *iptr);
函数功能把双精度数val分解为整数部分和小数部分,把整数部分存到iptr指向的单元.
函数返回: val的小数部分
参数说明: val 待分解的数
所属文件: <math.h>
使用范例:
#include <math.h>
#include <stdio.h>
int main()
{
double fraction,integer;
double number=100000.567;
fraction=modf(number,&integer);
printf("The whole and fractional parts of %lf are %lf and %lf",number,integer,fraction);
return 0;
}
________________________________________
函数名称: pow
函数原型: double pow(double x,double y);
函数功能计算以x为底数的y次幂,即计算x^y的值.
函数返回计算结果
参数说明: x-底数,y-幂数
所属文件: <math.h>
使用范例:
#include <math.h>
#include <stdio.h>
int main()
{
double x=2.0,y=3.0;
printf("%lf raised to %lf is %lf",x,y,pow(x,y));
return 0;
}
________________________________________
函数名称: sqrt
函数原型: double sqrt(double x);
函数功能计算x的开平方.
函数返回计算结果
参数说明: x>=0
所属文件: <math.h>
使用范例:
#include <math.h>
#include <stdio.h>
int main()
{
double x=4.0,result;
result=sqrt(x);
printf("The square root of %lf is %lf",x,result);
return 0;
}
________________________________________
函数名称: hypot
函数原型: double hypot(double x,double y)
函数功能已知直角三角形两个直角边长度,求斜边长度
函数返回斜边长度
参数说明: x,y-直角边长度
所属文件: <math.h>

#include <stdio.h>
#include <math.h>
int main()
{
double result;
double x=3.0;
double y=4.0;
result=hypot(x,y);
printf("The hypotenuse is: %lf",result);
return 0;
}
________________________________________
函数名称: poly
函数原型: double poly(double x,int degree,double coeffs[])
函数功能计算项式
函数返回多项式的计算结果
参数说明计算c[n]*x^n+c[n-1]x^n-1+.....+c[1]*x+c[0]
所属文件: <math.h>

#include <stdio.h>
#include <math.h>
int main()
{
double array[]={-1.0,5.0,-2.0,1.0};
double result;
result=poly(2.0,3,array);
printf("The polynomial: x**3 - 2.0x**2 + 5x - 1 at 2.0 is %lf",result);
return 0;
}
________________________________________
函数名称: matherr
函数原型: int matherr(struct exception *e)
函数功能数学错误计算处理程序
函数返回:
参数说明该函数不能被直接调用,而是被库函数_matherr()调用
所属文件: <math.h>

#include<math.h>
int matherr(struct exception *a)
{
return 1;
}
________________________________________
函数名称: ldexp
函数原型: double ldexp(double x,int exponent)
函数功能计算x*2exponent次幂,即2*pow(2,exponent)的数值
函数返回:
参数说明:
所属文件: <math.h>

#include <stdio.h>
#include <math.h>
int main()
{
double value;
double x=2;
value=ldexp(x,3);
printf("The ldexp value is: %lf",value);
return 0;
}

原创粉丝点击