在Dev C 上运行一个关于pow函数的小程序遇到的一点儿问题。。。

[复制链接]
查看11 | 回复1 | 2011-4-14 11:28:29 | 显示全部楼层 |阅读模式
在Dev c中运行一下C程序,
#include stdio.h
#include math.h
int main()
{
int a,b;
b=4;
a=pow(10,b);
printf(\"%d\",a);
system(\"pause\");
}
结果是9999
而运行
#include stdio.h
#include math.h
int main()
{
int a,b;
b=4;
a=pow(10,4);
printf(\"%d\",a);
system(\"pause\");
}
结果是10000,而两个小程序,第一个当中只是将pow函数中的“4”替换成了“b”,结果就不一样了,为什么呢?
回复

使用道具 举报

千问 | 2011-4-14 11:28:29 | 显示全部楼层
<pre id=\"best-answer-content\" class=\"reply-text mb10\">是浮点数的关系,因为pow的值是浮点数,
只要把第一个程序改一下就没问题了,把a设为double.

#includestdio.h
#includemath.h

int main()
{
double a;

int b=4;
a=(pow(10,b));
printf(\"%f\",a);

system(\"pause\");
return 0;
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行