#includestdio.h
成都創(chuàng)新互聯(lián)公司是一家專業(yè)提供吳起企業(yè)網(wǎng)站建設(shè),專注與做網(wǎng)站、網(wǎng)站設(shè)計(jì)、H5技術(shù)、小程序制作等業(yè)務(wù)。10年已為吳起眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站設(shè)計(jì)公司優(yōu)惠進(jìn)行中。
#include math.h
void main()
{
float x=5,y;
y=log(x);
printf("%f\n",y);
}
擴(kuò)展資料:
C語(yǔ)言中使用對(duì)數(shù)函數(shù)的方法
log()函數(shù):返回以e為底的對(duì)數(shù)值
頭文件:
1#include
log() 函數(shù)返回以 e 為底的對(duì)數(shù)值,其原型為:
1double?log?(double?x);
log()用來計(jì)算以e為底的 x 的對(duì)數(shù)值,然后將結(jié)果返回。設(shè)返回值為 ret,則
1x = eret
如果 x 為負(fù)數(shù)或 0,則會(huì)發(fā)生錯(cuò)誤并設(shè)置 errno 值。錯(cuò)誤代碼:
EDOM:參數(shù)x 為負(fù)數(shù);
ERANGE:參數(shù)x
為零值,零的對(duì)數(shù)值無定義。
注意:使用 GCC 編譯時(shí)請(qǐng)加入-lm。
x的自然對(duì)數(shù)用log(x)表示
常用對(duì)數(shù)用log10(x)表示
#includestdio.h
#includemath.h
int main()
{int i;
for(i=1;i=10;i++)
printf("log10(%d)=%lf\n",i,log10(i));
return 0;
}
#include stdio.h#include math.h
void main()
{
double i = 2, j =4;
printf("log2,4 = %f\n",log(j)/log(i));
}
//log函數(shù)是以e為底的,還有一個(gè)log10以10為底,可以利用logi,j=loge,j/loge,i來算。
1、C語(yǔ)言中,有兩個(gè)log函數(shù),分別為log10和log函數(shù),具體用法如下:
2、函數(shù)名: log10
功 能: 對(duì)數(shù)函數(shù)log,以10為底
用 法: double log10(double x);
程序示例:
#include math.h
#include stdio.hint 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、函數(shù)名: log
功 能: 對(duì)數(shù)函數(shù)log,以e(2.71828)為底
用 法: double log(double x);
程序示例:
#include math.h
#include stdio.hint main(void)
{
double result;
double x = 800.6872;
result = log(x);
printf("The common log of %lf is %lf\n", x, result);
return 0;
}
網(wǎng)頁(yè)名稱:c語(yǔ)言怎么運(yùn)用對(duì)數(shù)函數(shù) c語(yǔ)言中對(duì)數(shù)函數(shù)
本文URL:http://aaarwkj.com/article18/hhpegp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、企業(yè)網(wǎng)站制作、定制網(wǎng)站、用戶體驗(yàn)、服務(wù)器托管、標(biāo)簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)