读书人

!为什么下面程序输出结果跟c prime p

发布时间: 2013-04-26 16:27:53 作者: rapoo

求助!!!!为什么下面程序输出结果跟c prime plus 不一样
#include <stdio.h>
double power (double n,int p);
int main(void)
{
double x,xpow;
int exp;

printf("Enter a number and the positive integer power");
printf(" to which\nthe number will be raised.Enter q");
printf(" to quit.\n");
while (scanf("%1f %d",&x,&exp)==2)
{
xpow = power(x,exp);
printf("%.3g to the power %d is %.5g\n",x,exp,xpow);
printf("Enter next pair of number or q to quit.\n");
}
printf("Hope you enjoyed this power trip -- bye!\n");
return 0;
}
double power(double n,int p)
{
double pow = 1;
int i;

for (i =1;i <= p;i++)
pow*=n;
return pow;
} C
[解决办法]
while (scanf("%1f %d",&x,&exp)==2)
改为
while (scanf("%lf %d",&x,&exp)==2)

是LF(是小写,大写让你区分开) 不是1f

读书人网 >C语言

热点推荐