<math.h>
头文件中。double round(double x);
#include <stdio.h> #include <math.h> int main() { double numbers[] = {3.14, 3.5, -3.5, 2.718, -2.718, 0.0}; double result; for(int i = 0; i < 6; i++) { result = round(numbers[i]); printf("round(%.3f) = %.3f\n", numbers[i], result); } return 0; }输出结果为:
round(3.140) = 3.000
round(3.500) = 4.000
round(-3.500) = -4.000
round(2.718) = 3.000
round(-2.718) = -3.000
round(0.000) = 0.000
本文链接:http://task.lmcjl.com/news/18211.html