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