📄 subject_39655.htm
字号:
<p>
序号:39655 发表者:annehyf1024 发表日期:2003-05-12 17:57:47
<br>主题:请教一个菜鸟问题!
<br>内容:a(x,y)产生f(x)a(0.5*x,0.3*y)b(y),令x=0.5*x,y=0.3*y再继续替换,总共迭代3次,该怎样编程?<BR>我编了一个递归函数<BR>int count =0;<BR>string a(int x,int y)<BR>{<BR> string s;<BR> if(count=MAX_COUNT)//MAX_COUNY为最大迭代次数<BR> return "FA(x,y)B";<BR> else<BR> {<BR> count++;<BR> string s="x+"+a(x*0.5,y*0.5);<BR> }<BR> return s;<BR>}<BR>总返回"FA(x,y)B",结束条件应该怎样设呢?<BR> <BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:qqwang 回复日期:2003-05-12 20:33:17
<br>内容:判断没问题,<BR>是你的string变量定义的有问题。。<BR>string是局部变量啦,<BR>每次修改都是修改的函数内部的string变量,<BR>把string设为static......
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:annehyf1024 回复日期:2003-05-12 21:07:49
<br>内容:不对,我把s设为全局变量static string s,还是原样
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:qqwang 回复日期:2003-05-13 12:00:04
<br>内容:<BR>//我仔细看了看,程序还有错误,修改如下:<BR>int count =0;<BR>string a(int x,int y)<BR>{<BR> static string s; //这里应该用静态变量<BR> // string s;<BR> if(count==MAX_COUNT) //判断相等用==,而不是赋值运算符<BR>// if(count=MAX_COUNT)//MAX_COUNY为最大迭代次数<BR> return "FA(x,y)B";<BR> else<BR> {<BR> count++;<BR> s="x+"+a(x*0.5,y*.5);//这里string不能重复声明为局部变量<BR> //string s="x+"+a(x*0.5,y*0.5);<BR> }<BR> return s;<BR>}<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -