给个机会大神们,行侠仗义哦,嘻嘻
#include"stdio.h"int main(void)
{
double power(double a, double b);
double x = 2.0, y = 3.0, result;
//不知为何,底数是2的时候,无论指数怎么变,这个程式可以求出正确的POWER,一旦换个底数就不对了{:7_166:}
result = power(x, y);
printf("%lf raised to %lf is %lf\n",x, y, result);
return 0;
}
double power(double a, double b)
{
double z;
int c = 1;
z = a * a;
do
{
z=z*a;
c++;
}
while(c <= b);
return z = z / 4;
}
欣欣celin 发表于 2014-3-10 22:49 static/image/common/back.gif
谢谢,不明白“ *= ”是什么意思??百度没有
t*=a;等价于t=t*a; 你的power算法不对。。。帮你改了
double power(double a, double b)
{
double z;
int c;
z = a ;
for(c=1;c<b;c++)
z*=a;
return z;
}
zheyitian 发表于 2014-3-10 22:33 static/image/common/back.gif
你的power算法不对。。。帮你改了
double power(double a, double b)
谢谢{:5_110:},可是“ *= ”是什么意思??{:5_94:} 感觉应该这样写
double power(double a, double b)
{
double t=1;
for (double i=0;i<b;i++)
{
t*=a;
}
return t;
} machimilk 发表于 2014-3-10 22:44 static/image/common/back.gif
感觉应该这样写
double power(double a, double b)
{
谢谢,不明白“ *= ”是什么意思??百度没有 非常感谢,最于明白了{:5_109:}
页:
[1]