C语言中log函数怎么使用啊

C语言中log函数怎么使用啊,第1张

1、C语言中,有两个log函猛神或数,分别为log10和log函数,具体用法如下:

2、函数名: log10

功 能: 对数函数log,以10为底

用 法: double log10(double x)

程序示例:

#include <math.h>

#include <stdio.h>int main(void)

{

double result

double x = 800.6872

result = log10(x)

printf("The common log of %lf is %lf\n", x, result)

return 0

}

3、函数名: log

功 能: 对数函数log,以e(2.71828)为瞎升底

用 法: double log(double x)

程序示例枝伍:

#include <math.h>

#include <stdio.h>int main(void)

{

double result

double x = 800.6872

result = log(x)

printf("The common log of %lf is %lf\n", x, result)

return 0

}

其实就相当于 *** 作.txt文件一样  

你换下后缀就行了。示例如下:

// 如果你用心学一下PASCAL的基础知识就会看明白的.

// astr是需要记录的字符串内容, FN: 日志文件的名称, 默认为程序名称后加log.txt

procedure LogToFile(astr: string fn: string = 'AppLog')

var

  f: TextFile // 声明文件类型的变量

begin

  astr := formatdatetime('yy/mm/dd HH:nn', now) + ':'+ astr // 在字符串前加上日期

  if fn = 'AppLog' then

    fn := ChangeFileExt(GetModuleName(HInstance), '.' + formatdatetime('yymmdd', now) + '.log.txt') // 如

果不指定文件名称,则使用程序名称加.log.txt为日志名称

  AssignFile(f, fn) // 关联文件变量核者到指定的文件名

  try

    if FileExists(fn) then 

      Append(f) // 如果文件已经存在则设为追加模式

    else Rewrite(f) //否则重写一个新的文件.

    Writeln(f, astr) // 写入内容到日志文件

    { insert code here 尘烂that would require a Flush before closing the file }

    Flush(f) { ensures that the text was actually written to file  刷新缓冲,确保内容已经写入文件}

  finally

 改兄薯   CloseFile(f) // 关闭打开的文件

  end

end


欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/yw/12345464.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-22
下一篇2023-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存