下面这个程序在Vc6.0中运行正常,而在code::block 版本13.12,无法传递正常参数,求解
#include<stdio.h>double po2wer(double x,double y);
int main()
{
double a,b ,result ;
a =2.0 ;
b =3.0 ;
result =po2wer(a,b) ;
printf("%lf",result) ;
}
double po2wer(double x, double y)
{
double z=1.0;
printf("x=%lf,y=%lf\n",x,y) ;
while(y)
{
z = z*x;
--y;
}
printf("z=%lf\n",z) ;
return z;
}
你的while (y)不太好!y是浮点,容易造成错误。#include<stdio.h>
double po2wer(double x,int i);
int main() {
double a=2.0,result;
int i=3;
result =po2wer(a,i);
printf("%lf\n",result);
return 0;
}
double po2wer(double x,int i) {
double z=1.0;
printf("x=%lf\n",x);
while(i)
{
z = z*x;
--i;
}
printf("z=%lf\n",z);
return z;
}
楼上正解// 我的意思是如何在code::block 中传递double 类型的数据。。?
页:
[1]