问题描述
我在VB .NET类中,并且其中一个任务是使用循环来生成所有毕达哥拉斯三元组的列表,其中legA和legB
到目前为止我已经这样做了:
很明显,但是你能指出一些更重要的方向吗?我(正如我顺便提到的那样)一直绞尽脑汁试图想出一个解决方案,但我感到很茫然(通常这些事情很快就会发生)。
感谢你回复和任何未来的帮助(当然,这都属于道德范围)。
当你接受时,我正在尝试(作为一名教师)让你想到如何解决问题。还有一些想法:(1)你真的需要三个循环吗?从trig,你知道hyp平方=其他两边的平方和。 (2)减少对小的限制,并写出For循环的变量,这样你就可以看到如何使迭代只考虑一次可能性;例如,当LeqA For循环开启时,是否有任何理由在1处启动LegB循环?你还没盖过那个案子吗?保持微笑! --Sam
I am in a VB .NET class, and one of the assignments is to use loops to generate a list of all the pythagorean triples where legA and legB <100 and hypotenuse < 200, and then put this list into a listbox.
I have done this so far:
Clearly, but could you point me in the direction of something somewhat more substantial? I have (as I mentioned in passing) been racking my brain trying to come up with a solution, but am at a loss (normally these things come pretty quickly).
Thanks for the reply and any future help (that, of course, falls within the limits of morality).
As you picked up, I''m trying (as a teacher myself) to make you think of how to solve the problem. A couple more ideas: (1) Do you really need three loops? From trig, you know that the hyp squared = the sum of the squares of the other two sides. (2)Reduce you side limits to something small and write out the variables of the For loop, so that you can see how to make the iterations only cove the possibilities once; for example, when the LeqA For loop is on 2, is there any reason to start the LegB loop at 1? Haven''t you already covered that case? Keep smiling! --Sam
这篇关于毕达哥拉斯三倍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!