pinrtf("\n%d^%d=%0.0f",x,y,GetPower(x,y));}
printf("exponent=%d\n",GetPower(a,b));}
intGetPower(intx,inty){if(y==0)return1;elsereturnx*GetPower(x,y-1);}
intgetpower(intx,inty){if(y==1)returnx;elsereturnx*getpower(x,y-1);}doublegetpower(doublex,inty){if(y==1)returnx;elsereturnx*getpower(x,y-1);}...
floatexponentiation(floatx,inty){if(y==1){returnx;}if(y==-1){return1/x;}returny>0?x*exponentiation(x,y-1):(1/x)*exponentiation(x,y+1);}...
X*GetPower(x,y-1)這個(gè)是是實(shí)現(xiàn)函數(shù)的自身遞推,把大問題一步一步縮小,最后知道y==1,然后回歸。
;/*提示輸入冪次方*/printf("inputthepowerofit:");/*輸入一個(gè)整數(shù)*/scanf("%d",&power);/*用輸入的兩個(gè)數(shù)據(jù),調(diào)用遞歸函數(shù)*/answer=getpower(num,power);printf("結(jié)果是:%ld\n",answer);}...
getPower(doublex,inty)就可以了目前你的定義的情況下getPower(b,m)找不到最匹配的就是(double,int)只能找次匹配的,找到了(double,double)和(int,int)編譯器只能說我也不知道你要調(diào)用哪一個(gè)了...
題目要求計(jì)算x的y次冪,x,y都是整數(shù),且用遞歸函數(shù)計(jì)算,你這兩點(diǎn)都沒有達(dá)到.按照題目要求我把程序改過來了,你看看吧.include<stdio.h>doublegetpower(intx,inty);intmain(){intx,y;while(~scanf("%d,%d"...
你看一下我寫的:longintgetpower(intx,inty){if(x==0){return0;}elseif(y==0){return1;}else{returnx*getpower(x,y-1);}}