c语言中绝对值怎么求?
来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/07/13 14:39:50
c语言中绝对值怎么求?
![c语言中绝对值怎么求?](/uploads/image/z/15733140-60-0.jpg?t=c%E8%AF%AD%E8%A8%80%E4%B8%AD%E7%BB%9D%E5%AF%B9%E5%80%BC%E6%80%8E%E4%B9%88%E6%B1%82%3F)
函数名: 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函数参数与返回值为实型.
以上是百科上的说明.