首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

!为什么下面程序输出结果跟c prime plus 不一样

2013-04-26 
求助!!!!为什么下面程序输出结果跟c prime plus 不一样#include stdio.hdouble power (double n,int p)

求助!!!!为什么下面程序输出结果跟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

热点排行