原型:double log (double x);
头文件:math.h
功能:计算以e 为底的对数值
程序例:
#include math.h
#include stdio.h
int main(void)
{
double result;
result = log(x);
printf("The common log of %lf is %lf\n", x, result);
return 0;
}
C语言里面有该函数,所以输入一个双精度浮点数,对其进行函数变换即可生成其对数.
还有如果你的意思是输入对数进行幂运算的话有下面这个函数
原型:extern float pow(float x, float y);
用法:#include math.h
功能:计算x的y次幂.
说明:x应大于零,返回幂指数的结果.
举例:
// pow.c
#include stdlib.h
#include conio.h
void main()
getchar();
#includestdio.h
#includemath.h
intmain(){
printf("%f\n",log(10));//以e为底的对数函数
printf("%f\n",log10(100));//以10为底的对数函数
printf("%f\n",exp(1));//计算自然常数e
return0;
扩展资料
模拟一个log日志的写入
#includestdarg.h
#includetime.h
intwrite_log(FILE*pFile,constchar*format,...)
va_listarg;
intdone;
va_start(arg,format);
time_ttime_log=time(NULL);
structtm*tm_log=localtime(time_log);
done=vfprintf(pFile,format,arg);
va_end(arg);
fflush(pFile);
returndone;
intmain()
fclose(pFile);
首先在C语言中要用到指数、对数的相关公式,需要引入math.h.另外ln是以e为底数,lg是以10为底数.
代码如下:
double exponent, base;
exponent = 100;
扩展资料:
math.h文件中包含的函数主要分为以下几类:
①.、三角函数、反三角函数、双曲三角函数.
涉及参数类型为double类型.
参考资料:
百度百科——换底公式
百度百科——math.h
①.、C语言中,有两个log函数,分别为log10和log函数,具体用法如下:
功 能: 对数函数log,以10为底
用 法: double log10(double x);
程序示例:
#include stdio.hint main(void)
result = log10(x);
用 法: double log(double x);
x的自然对数用log(x)表示
常用对数用log10(x)表示
int main()
{int i;
for(i=1;i=10;i++)
printf("log10(%d)=%lf\n",i,log10(i));
以上就是土嘎嘎小编为大家整理的c语言log函数怎么写的相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!