log3在c语言中怎样表示

如题所述

#include<stdio.h>

#include<math.h>

intmain(){

printf("%f\n",log(10));//以e为底的对数函数

printf("%f\n",log10(100));//以10为底的对数函数

printf("%f\n",log(8)/log(2));//计算log2^8,运用换底公式

printf("%f\n",exp(1));//计算自然常数e

return0;

}

扩展资料

模拟一个log日志的写入

#include<stdio.h>

#include<stdarg.h>

#include<time.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);

fprintf(pFile,"%04d-%02d-%02d%02d:%02d:%02d",tm_log->tm_year+1900,tm_log->tm_mon+1,tm_log->tm_mday,tm_log->tm_hour,tm_log->tm_min,tm_log->tm_sec);

done=vfprintf(pFile,format,arg);

va_end(arg);

fflush(pFile);

returndone;

}

intmain()

{

FILE*pFile=fopen(“123.txt”,“a”);

write_log(pFile,"%s%d%f\n","isrunning",10,55.55);

fclose(pFile);

return0;

}

温馨提示:内容为网友见解,仅供参考
第1个回答  2017-12-12

不知道是log 3还是以3为底的对数函数?

函数就一个:

double log(double) /* 在<math.h>中*/

表示自然对数函数(即数学中的ln)

如果要换成其他底的对数,可以用换底公式:相除即可。

比如以3为底,27的对数,可以用27的自然对数除以3的自然对数:

log(27) / log(3)

本回答被网友采纳
第2个回答  2017-12-12
你在MATLAB 或是其他里面用log不好吗?
第3个回答  2017-12-10
请问两个竖线中间有空格吗
相似回答