pow()函數(shù)用來求x的y次冪,x、y及函數(shù)值都是double型 ,其原型為:double pow(double x, double y)。

我們提供的服務(wù)有:網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、微信公眾號(hào)開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、田家庵ssl等。為超過千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的田家庵網(wǎng)站制作公司
實(shí)例代碼如下:
#includestdio.h
#includemath.h
void main()
{
double x = 2, y = 10;
printf("%f\n",pow(x, y));
return 0;
}
擴(kuò)展資料:
在調(diào)用pow函數(shù)時(shí),可能導(dǎo)致錯(cuò)誤的情況:
如果底數(shù) x 為負(fù)數(shù)并且指數(shù) y 不是整數(shù),將會(huì)導(dǎo)致 domain error錯(cuò)誤。
如果底數(shù) x 和指數(shù) y 都是 0,可能會(huì)導(dǎo)致 domain error?錯(cuò)誤,也可能沒有;這跟庫的實(shí)現(xiàn)有關(guān)。
如果底數(shù) x 是 0,指數(shù) y 是負(fù)數(shù),可能會(huì)導(dǎo)致?domain error 或pole error 錯(cuò)誤,也可能沒有;這跟庫的實(shí)現(xiàn)有關(guān)。
如果返回值 ret 太大或者太小,將會(huì)導(dǎo)致range error 錯(cuò)誤。
錯(cuò)誤代碼:
如果發(fā)生 domain error 錯(cuò)誤,那么全局變量 errno 將被設(shè)置為? EDOM;
如果發(fā)生 pole error 或 range error 錯(cuò)誤,那么全局變量 errno 將被設(shè)置為 ERANGE。
參考資料:
pow函數(shù)——百度百科
原型:extern float pow(float x, float y);
用法:#include math.h
功能:計(jì)算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();
}
相關(guān)函數(shù):pow10
c語言中pow函數(shù)用的步驟。
電腦:華為MateBook14
系統(tǒng):Windows10
軟件:C語言1.0
1、首先,要加入頭文件math.h,其中pow(x,y);//其作用是計(jì)算x的y次方,x、y及函數(shù)值都是double型。
2、然后,在計(jì)算2的5次方,源代碼如下:#include"stdio.h"#include"math.h"main(){long total;int x = 2, y = 5;total = pow(x,y); /*調(diào)用pow函數(shù)*/printf("%ld",total);getch();}。
3、然后,在包含cmath頭文件,pow(4,3),第1個(gè)是底數(shù),第2個(gè)是指數(shù),#include?math.h printf("%f\n",?pow(1.2,?2));?//?結(jié)果1.44,1.2的平方。
4、然后,在C語言中,Pow函數(shù)這的是求一個(gè)數(shù)的多少此方,#include lt;math.hgt; #include lt;stdio.hgt; void main( void ) { double x = 2.0, y = 3.0, z; z =?pow( x, y ); printf("%.1f to the power of %.1f is %.1f\n",x, y, z ); } LZ。
5、然后,用功能來計(jì)算x的y次冪,說明x應(yīng)大于零,返回冪指數(shù)的結(jié)果://pow.c#include?#include?#include?void main(){printf("4^5=%f",pow(4.,5.));getchar();}相關(guān)函數(shù):pow10,添加頭文件#include math.h,注意參數(shù)類型及返回類型均為double,是double類型,也使用變量是int類型,要把類型進(jìn)行轉(zhuǎn)化。
網(wǎng)站欄目:c語言冪pow函數(shù)怎么用,c語言求冪函數(shù)pow
標(biāo)題路徑:http://chinadenli.net/article37/dseejsj.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、關(guān)鍵詞優(yōu)化、、軟件開發(fā)、品牌網(wǎng)站建設(shè)、網(wǎng)站導(dǎo)航
聲明:本網(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)