C++中math.h库函数
来源:互联网 发布:淘宝排名软件 编辑:程序博客网 时间:2024/06/04 20:00
C++中math.h库函数
转自:http://blog.sina.com.cn/s/blog_99fd464b0100xoqo.html
abs
原型:extern int abs(int x);
用法:#include <math.h>
功能:求整数x的绝对值
说明:计算|x|, 当x不为负时返回x,否则返回-x
举例:
// abs.c
#include <syslib.h>
#include <math.h>
main()
{
int x;
clrscr(); // clear screen
x=-5;
printf("|%d|=%d\n",x,abs(x));
x=0;
printf("|%d|=%d\n",x,abs(x));
x=+5;
printf("|%d|=%d\n",x,abs(x));
getchar();
return 0;
}
相关函数:fabs
acos
原型:extern float acos(float x);
用法:#include <math.h>
功能:求x(弧度表示)的反余弦值
说明:x的定义域为[-1.0,1.0],值域为[0,π]。
举例:
// acos.c
#include <syslib.h>
#include <math.h>
main()
{
float x;
clrscr(); // clear screen
textmode(0x00); // 6 lines per LCD screen
x=0.32;
printf("acos(%.2f)=%.4f",x,acos(x));
getchar();
return 0;
}
相关函数:asin,atan,atan2,sin,cos,tan
asin
原型:extern float asin(float x);
用法:#include <math.h>
功能:求x(弧度表示)的反正弦值
说明:x的定义域为[-1.0,1.0],值域为[-π/2,+π/2]。
举例:
原型:extern int abs(int x);
用法:#include <math.h>
功能:求整数x的绝对值
说明:计算|x|, 当x不为负时返回x,否则返回-x
举例:
相关函数:fabs
acos
原型:extern float acos(float x);
用法:#include <math.h>
功能:求x(弧度表示)的反余弦值
说明:x的定义域为[-1.0,1.0],值域为[0,π]。
举例:
相关函数:asin,atan,atan2,sin,cos,tan
asin
原型:extern float asin(float x);
用法:#include <math.h>
功能:求x(弧度表示)的反正弦值
说明:x的定义域为[-1.0,1.0],值域为[-π/2,+π/2]。
举例: