1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <math.h> 4 5 int main() 6 { 7 //取整 8 printf("%ld\n",(long)19.999); 9 //保留0位小数部分 10 printf("%.lf\n",19.999); 11 12 //四舍五入 13 //(long)是取整最右边的数据,而数据与数据之间以运算符号分开 14 //所以一定要把数据和0.5用括号括起来,否则输出为0 15 printf("%ld\n",(long)(19.5+0.5)); 16 printf("%ld\n",(long)(19.49+0.5)); 17 printf("%ld\n",(long)(19.51+0.5)); 18 19 //整型用abs,实型用fabs 20 printf("%ld\n",abs(-5)); 21 printf("%lf\n",fabs(-5.123)); 22 return 0; 23 }