double power(double dot2 , int index2);
int main(void)
{
double dot1;
int index1;
double answer;
scanf("%Lf%d",&dot1,&index1);
answer = power(dot1,index1);
printf("%.3g",answer);
return 0;
}
double power(double dot2 , int index2)
{
int num;
double answer2 = 1;
if(index2 > 0 )
for(num = 0 ; num < index2 ; num ++)
answer2 *= dot2;
else if(index2 = 0)
answer2 = 1;
else(index2 < 0)
for(num = 0 ; num < -index2 ; num ++)
answer2 *= 1/dot2;
return answer2;
}
为什么这个函数power()不能计算 负幂?
每次第二个数输入负数总数输出1又是为什么?