常用math函数

1.fabs(double x) —取绝对值

#include <stdio.h>
#include <math.h>
int main(){
	double db = -12.56;
	printf("%.2f\n", fabs(db));
	return 0;
}

2.floor(double x) ——向下取整

  ceil(double x)——向上取整

#include <stdio.h>
#include <math.h>
int main(){
	double db1 = -5.2, db2 = 5.2;
	printf("%.0f %.0f\n", floor(db1), ceil(db1));
	printf("%.0f %.0f\n", floor(db2), ceil(db2));
	return 0;
}

猜你喜欢

转载自blog.csdn.net/gsj9086/article/details/83449575