C中的pow功能有问题 [英] Problem with the pow function in C

查看:130
本文介绍了C中的pow功能有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在程序中遇到了pow功能的问题。该函数是for循环的一部分,这里是代码部分:



for(year = 1; year< = 10; ++ year)
{

金额=本金*粉末(1.0 +税率,年份);

printf(%4u%21.2f \ n,年份,金额);

}



当我运行程序时,我收到以下错误消息:



/tmp/cc9xIlqs.o:在函数'main'中:

main.c :(。text + 0x84):未定义引用'pow'

collect2:错误:ld返回1退出状态



任何人都可以提供帮助吗?

解决方案

尝试将-lm开关添加到gcc命令以加载数学库:

 gcc MyProgram.c -o MyProgram -lm 


感谢。我的字体使得该建议看起来像1号而不是小写字母l。在我连接之前,我花了几次尝试。谢谢你的帮助。


I am running into a problem with the pow function in my program. The function is part of a for loop and here is the code section:

for( year = 1; year <= 10; ++year)
{
amount = principal * pow( 1.0 + rate, year);
printf( "%4u%21.2f\n", year, amount);
}

When I run my program I get the following error message:

/tmp/cc9xIlqs.o: In function 'main':
main.c: (.text+0x84): undefined reference to 'pow'
collect2: error: ld returned 1 exit status

Can anyone provide help with this?

解决方案

Try adding the -lm switch to your gcc command to load the math library:

gcc MyProgram.c -o MyProgram -lm


Thanks. My fonts have made that suggestion look like a number 1 instead of a lower case l. It took me a few tries before I even made the connection. Thanks for the help.


这篇关于C中的pow功能有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆