math_h函数以及其他一些库函数_人世知己

math.h函数以及其他一些库函数_人世知己百度空间 | 百度首页 | 登录 人世知己 主页博客相册|个人档案 |好友 查看文章
math.h函数以及其他一些库函数2009-11-30 21:19@函数名称: 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 到 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应在-1到1范围内.切记单位为弧度
所属文件: <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);
函数功能: 求e的x次幂
函数返回: 计算结果.幂的值
参数说明: 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<=x且x<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)
函数返回: 计算结果
参数说明:
所属文件: <ma

th.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*2的exponent次幂,即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;
}
int abs(int i) 返回整型参数i的绝对值
double cabs(struct complex znum) 返回复数znum的绝对值
double fabs(double x) 返回双精度参数x的绝对值
long labs(long n) 返回长整型参数n的绝对值
double exp(double x) 返回指数函数ex的值
double frexp(double value,int *eptr) 返回value=x*2n
中x的值,n存贮在eptr中
double ldexp(double value,int exp); 返回value*2exp的值
double log(double x) 返回logex的值
double log10(double x) 返回log10x的值
double pow(double x,double y) 返回xy的值
double pow10(int p) 返回10p的值
double sqrt(double x) 返回+√x的值
double acos(double x) 返回x的反余弦cos-1(x)值,x为弧度
double asin(double x) 返回x的反正弦sin-1(x)值,x为弧度
double atan(double x) 返回x的反正切tan-1(x)值,x为弧度
double atan2(double y,double x) 返回y/x的反正切tan-1(x)值,y的x为弧度
double cos(double x) 返回x的余弦cos(x)值,x为弧度
double sin(double x) 返回x的正弦sin(x)值,x为弧度
double tan(double x) 返回x的正切tan(x)值,x为弧度
double cosh(double x) 返回x的双曲余弦cosh(x)值,x为弧度
double sinh(double x) 返回x的双曲正弦sinh(x)值,x为弧度
double tanh(double x) 返回x的双曲正切tanh(x)值,x为弧度
double hypot(double x,double y) 返回直角三角形斜边的长度(z),
x和y为直角边的长度,z2=x2+y2
double ceil(double x) 返回不小于x的最小整数
double floor(double x) 返回不大于x的最大整数
void srand(unsigned seed) 初始化随机数发生器
int rand() 产生一个随机数并返回这个数
double poly(double x,int n,double c[])从参数产生一个

多项式
double modf(double value,double *iptr)将双精度数value分解成尾数和阶
double fmod(double x,double y) 返回x/y的余数
double frexp(double value,int *eptr) 将双精度数value分成尾数和阶
double atof(char *nptr) 将字符串nptr转换成浮点数并返回这个浮点数
double atoi(char *nptr) 将字符串nptr转换成整数并返回这个整数
double atol(char *nptr) 将字符串nptr转换成长整数并返回这个整数
char *ecvt(double value,int ndigit,int *decpt,int *sign)
将浮点数value转换成字符串并返回该字符串
char *fcvt(double value,int ndigit,int *decpt,int *sign)
将浮点数value转换成字符串并返回该字符串
char *gcvt(double value,int ndigit,char *buf)
将数value转换成字符串并存于buf中,并返回buf的指针
char *ultoa(unsigned long value,char *string,int radix)
将无符号整型数value转换成字符串并返回该字符串,radix为转换时所用基数
char *ltoa(long va

相关文档
最新文档