原型:double log (double x);
成都創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、網(wǎng)站制作、網(wǎng)站營銷推廣、網(wǎng)站開發(fā)設(shè)計,對服務(wù)木托盤等多個行業(yè)擁有豐富的網(wǎng)站建設(shè)及推廣經(jīng)驗。成都創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司成立于2013年,提供專業(yè)網(wǎng)站制作報價服務(wù),我們深知市場的競爭激烈,認真對待每位客戶,為客戶提供賞心悅目的作品。 與客戶共同發(fā)展進步,是我們永遠的責任!
頭文件:math.h
功能:計算以e 為底的對數(shù)值
程序例:
#include math.h
#include stdio.h
int main(void)
{
double result;
double x = 321.123;
result = log(x);
printf("The common log of %lf is %lf\n", x, result);
return 0;
}
C語言里面有該函數(shù),所以輸入一個雙精度浮點數(shù),對其進行函數(shù)變換即可生成其對數(shù)。
還有如果你的意思是輸入對數(shù)進行冪運算的話有下面這個函數(shù)
原型:extern float pow(float x, float y);
用法:#include math.h
功能:計算x的y次冪。
說明:x應(yīng)大于零,返回冪指數(shù)的結(jié)果。
舉例:
// pow.c
#include stdlib.h
#include math.h
#include conio.h
void main()
{
printf("4^5=%f",pow(4.,5.));
getchar();
}
1、C語言中,有兩個log函數(shù),分別為log10和log函數(shù),具體用法如下:
2、函數(shù)名: log10
功 能: 對數(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
功 能: 對數(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;
}
1、C語言中,有兩個log函數(shù),分別為log10和log函數(shù),具體用法如下:
2、函數(shù)名: log10
功 能: 對數(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
功 能: 對數(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;
}
c 里直接提供的是 以 e 為底的自然對數(shù) log ,和 以 10 為底的常用對數(shù) log10
其他對數(shù)寫個函數(shù)就可以
#include stdio.h
#include math.h
double loga(double n, double base);
int main (void)
{
double a, b, c;
a = log(exp(1));
b = log10(10);
c = loga(100, 5);
printf("%lf %lf %lf", a, b, c);
}
double loga(double n, double base)
{ return log(n) / log(base);}
這個應(yīng)該是你想要的
#includestdio.h
#include math.h
void main()
{
float x=5,y;
y=log(x);
printf("%f\n",y);
}
擴展資料:
C語言中使用對數(shù)函數(shù)的方法
log()函數(shù):返回以e為底的對數(shù)值
頭文件:
1#include
log() 函數(shù)返回以 e 為底的對數(shù)值,其原型為:
1double?log?(double?x);
log()用來計算以e為底的 x 的對數(shù)值,然后將結(jié)果返回。設(shè)返回值為 ret,則
1x = eret
如果 x 為負數(shù)或 0,則會發(fā)生錯誤并設(shè)置 errno 值。錯誤代碼:
EDOM:參數(shù)x 為負數(shù);
ERANGE:參數(shù)x
為零值,零的對數(shù)值無定義。
注意:使用 GCC 編譯時請加入-lm。
double log(double x),函數(shù)返回x的自然對數(shù),即lnx,
double log10(double x),函數(shù)返回x的以10為底的對數(shù).
網(wǎng)頁名稱:C語言怎么輸入對數(shù)函數(shù) 用c語言編寫自己的對數(shù)函數(shù)
鏈接分享:http://www.muchs.cn/article16/hhiodg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、電子商務(wù)、網(wǎng)站改版、網(wǎng)站維護、網(wǎng)站策劃、域名注冊
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)