extern float pow(float x, float y)
從事成都IDC機(jī)房托管,服務(wù)器租用,云主機(jī),虛擬空間,主機(jī)域名,CDN,網(wǎng)絡(luò)代維等服務(wù)。
用法:#include math.h
功能:計(jì)算x的y次冪。
說(shuō)明: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語(yǔ)言是一門通用計(jì)算機(jī)編程語(yǔ)言,應(yīng)用廣泛。C語(yǔ)言的設(shè)計(jì)目標(biāo)是提供一種能以簡(jiǎn)易的方式編譯、處理低級(jí)存儲(chǔ)器、產(chǎn)生少量的機(jī)器碼以及不需要任何運(yùn)行環(huán)境支持便能運(yùn)行的編程語(yǔ)言。
pow()函數(shù)用來(lái)求x的y次冪,x、y及函數(shù)值都是double型 ,其原型為:double pow(double x, double y)。
實(shí)例代碼如下:
#includestdio.h
#includemath.h
void main()
{
double x = 2, y = 10;
printf("%f\n",pow(x, y));
return 0;
}
相關(guān)內(nèi)容:
C++提供以下幾種pow函數(shù)的重載形式:
double pow(double X,int Y);
float pow(float X,float Y);
float pow(float X,int Y);
long double pow(long double X,long double Y);
long double pow(long double X,int Y);
使用的時(shí)候應(yīng)合理設(shè)置參數(shù)類型,避免有多個(gè)“pow”實(shí)例與參數(shù)列表相匹配的情況。
其中較容易發(fā)生重載的是使用形如:
int X,Y;
int num=pow(X,Y);
這是一個(gè)比較常用的函數(shù),但是編譯器會(huì)提醒有多個(gè)“pow”實(shí)例與參數(shù)列表相匹配。
可以使用強(qiáng)制類型轉(zhuǎn)換解決這個(gè)問(wèn)題:num=pow((float)X,Y)。
#includestdio.h
#includeiostream
#includemath.h
#includestring.h
using namespace std;
#define N 10
int function(char a[])
{
int i,c,sum=0;
int b[N];
c=strlen(a);
for(i=0;ic;i++)
{
if('A'=a[i]a[i]='E')
b[i]=a[i]-55;
else if('a'=a[i]a[i]='e')
b[i]=a[i]-87;
else
b[i]=a[i]-48;//因?yàn)閏har類型的數(shù)字0對(duì)應(yīng)十進(jìn)制的48,這下你就懂了吧?。?!
}
coutendl;
for(i=0;ic;i++)
sum=int(sum+b[i]*pow(16,c-1-i));
return sum;
}
main()
{
char a[N];
printf("Please input a string:\n");
gets(a);
printf("%d\n",function(a));
return 0;
}
你可以試一下子,我已經(jīng)再改的地方做了注釋,而且,必須將char類型數(shù)字改成int型的數(shù)字,否則會(huì)產(chǎn)生不確定的錯(cuò)誤?。。∠M麧M意,給分啊親!
1,要加入頭文件 math.h
2,pow(x,y);//其作用是計(jì)算x的y次方。x、y及函數(shù)值都是double型
例:
我要計(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();
}
當(dāng)前文章:pow函數(shù)c語(yǔ)言怎么寫 pow用法c語(yǔ)言
網(wǎng)頁(yè)鏈接:http://www.rwnh.cn/article32/hicepc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化、搜索引擎優(yōu)化、定制網(wǎng)站、企業(yè)網(wǎng)站制作、網(wǎng)站制作、自適應(yīng)網(wǎng)站
聲明:本網(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í)需注明來(lái)源: 創(chuàng)新互聯(lián)
營(yíng)銷型網(wǎng)站建設(shè)知識(shí)