<math.h>
头文件中。double log10(double x);
#include <stdio.h> #include <math.h> #include <errno.h> int main() { double numbers[] = {1.0, 10.0, 100.0, -4.0, 0}; double result; for(int i = 0; i < 5; i++) { errno = 0; // 清除先前的错误 result = log10(numbers[i]); if(errno == 0) { printf("log10(%.2f) = %.2f\n", numbers[i], result); } else { printf("Error in calculating log10(%.2f)\n", numbers[i]); } } return 0; }输出结果为:
log10(1.00) = 0.00
log10(10.00) = 1.00
log10(100.00) = 2.00
Error in calculating log10(-4.00)
Error in calculating log10(0.00)
本文链接:http://task.lmcjl.com/news/15180.html