(1)pow函数返回值是double类型
(2)pow原型
double pow(double x,double y);
(3)sqrt原型
double sqrt(double x);
当输出时函数值赋给整型就会出错:
int main()d
{int N = 1;scanf("%d",&N);for(int i = 0;i<=N;i++){printf("pow(10,%d) = %d\n",i,pow(10,i));}return 0;
}
结果
18
pow(10,0) = 0
pow(10,1) = 0
pow(10,2) = 0
pow(10,3) = 0
pow(10,4) = 0
pow(10,5) = 0
pow(10,6) = 0
pow(10,7) = 0
pow(10,8) = 0
pow(10,9) = 0
pow(10,10) = 536870912
pow(10,11) = -402653184
pow(10,12) = -1577058304
pow(10,13) = -448790528
pow(10,14) = 512753664
pow(10,15) = 640942080
pow(10,16) = 937459712
pow(10,17) = -2049400832
pow(10,18) = 1733216256
把%d换成%f就对了
for(int i = 0;i<=N;i++){printf("pow(10,%d) = %f\n",i,pow(10,i));}
5
pow(10,0) = 1.000000
pow(10,1) = 10.000000
pow(10,2) = 100.000000
pow(10,3) = 1000.000000
pow(10,4) = 10000.000000
pow(10,5) = 100000.000000