本文目錄一覽:
- 1、c語言怎樣輸入對數
- 2、lg1.5在C語言程序中如何表示
- 3、如何用c語言編輯出lg函數並帶值?
- 4、c語言中的log,ln,lg怎麼編寫
- 5、C語言中lg怎麼編寫?
- 6、C語言中log函數怎麼使用啊
c語言怎樣輸入對數
#includestdio.h
#include math.h
void main()
{
float x=5,y;
y=log(x);
printf(“%f\n”,y);
}
擴展資料:
C語言中使用對數函數的方法
log()函數:返回以e為底的對數值
頭文件:
1#include
log() 函數返回以 e 為底的對數值,其原型為:
1double log (double x);
log()用來計算以e為底的 x 的對數值,然後將結果返回。設返回值為 ret,則
1x = eret
如果 x 為負數或 0,則會發生錯誤並設置 errno 值。錯誤代碼:
EDOM:參數x 為負數;
ERANGE:參數x
為零值,零的對數值無定義。
注意:使用 GCC 編譯時請加入-lm。
lg1.5在C語言程序中如何表示
表示為log10(1.5)即可。lg1.5中的lg是數學中以10為底的對數函數的一種書寫表示,在C語言中對應的庫函數名是log10。比如:
//#include “stdafx.h”//If the vc++6.0, with this line.
#include “stdio.h”
#include “math.h”//log10在這個頭文件中
int main(void){
printf(“lg1.5 = %g\n”,log10(1.5));
return 0;
}輸出是lg1.5
=
0.176091
如何用c語言編輯出lg函數並帶值?
#include stdio.h
#include math.h
void main()
{
float x;
scanf(“%f”,x);
(x=(float)0)?printf(“輸入有誤!”):printf(“lgx=%f”,log10(x));
}
運行示例截圖:
c語言中的log,ln,lg怎麼編寫
首先在C語言中要用到指數、對數的相關公式,需要引入math.h。另外ln是以e為底數,lg是以10為底數。
代碼如下:
#includestdio.h
#includemath.h
void main()
{
double exponent, base;
exponent = 3.14;
printf(“ln(%f) = %.2f\n”, exponent, log(exponent));//以e為底數的對數
exponent = 100;
printf(“lg(%.f) = %.2f\n”, exponent, log10(exponent));//以10為底數的對數
base = 5, exponent = 100;
printf(“log_%.f(%.f) = %.2f\n”, base, exponent, log(exponent)/log(base));//換底公式
return 0;
}
在求log_5(100)時需要用到「換底公式」:log_5(100) = ln(100)/ln(5)。
擴展資料:
math.h文件中包含的函數主要分為以下幾類:
1、三角函數、反三角函數、雙曲三角函數。
2、指數、對數。
3、取整、絕對值。
4、標準化浮點數。
涉及參數類型為double類型。
參考資料:
百度百科——換底公式
百度百科——math.h
C語言中lg怎麼編寫?
在 C中預處理先加上頭文件math.h然後log(x)便是常用對數,x為double型變數,望採納
C語言中log函數怎麼使用啊
1、C語言中,有兩個log函數,分別為log10和log函數,具體用法如下:
2、函數名: log10
功 能: 對數函數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、函數名: log
功 能: 對數函數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;
}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/183201.html