c语言中绝对值怎么求?
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/17 03:11:08
c语言中绝对值怎么求?
函数名: abs
功 能: 求整数的绝对值
头文件:math.h
函数原型:int abs(int i);
程序例:
#include
#include
int main(void)
{
int number = -1234;
printf("number: %d absolute value: %d\n", number, abs(number));
return 0;
}
在C语言中还有fabs,也是求绝对值的,不同的是,fabs函数参数与返回值为实型.
以上是百科上的说明.
功 能: 求整数的绝对值
头文件:math.h
函数原型:int abs(int i);
程序例:
#include
#include
int main(void)
{
int number = -1234;
printf("number: %d absolute value: %d\n", number, abs(number));
return 0;
}
在C语言中还有fabs,也是求绝对值的,不同的是,fabs函数参数与返回值为实型.
以上是百科上的说明.