毕达哥拉斯三重奏 [英] Pythagorean triple

查看:116
本文介绍了毕达哥拉斯三重奏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的编程课中有一项任务。它是以下。  

I've got a task in my programming class. It's the following.  

毕达哥拉斯三元组是三个整数,a< b< c其中a ^ 2 + b ^ 2 = c ^ 2例如,3 ^ 2 + 4 ^ 2 = 5 ^ 2恰好有一个毕达哥拉斯三元组,其中a + b + c = 1000.找到它。

a Pythagorean triple is three integers, a <b <c where a ^ 2 + b ^ 2 = c ^ 2 for example, 3 ^ 2 + 4 ^ 2 = 5 ^ 2 There is exactly a Pythagorean triple where a + b + c = 1000. Find it.

我可以使用varabels作为u<<< b< c和a + b + c = 1000来找到a,b和c是或者我应该做什么?

Can i use varabels as uctual variabels like a < b <c and a + b + c = 1000 to find what a, b and c is or should i do something else?

推荐答案

是的,您可以像在普通公式中一样使用变量。您可以通过程序更改这些变量,以便找到解决方案。例如,您可能首先尝试确定它是什么。为此,您需要调整
变量a的值,直到获得可行的内容为止。您将调整所有变量,直到您得出最终答案。只有变量才能在这种情况下工作,因为你必须能够在运行时读/写它们。

Yes you can use variables like you would in a normal formula. Those variables can be changed by your program in order to find the solution. For example you might start by trying to determine what a is. For that you'll need to be adjusting the value of the variable a until you get something that will work. You'll be adjusting all your variables until you come up with the final answer. Only variables would work in this situation as you have to be able to read/write them at runtime.

当然你的所有代码都可能包含在你的一组函数/方法中'用来做实际的计算。例如,您可能具有执行实际计算的高级功能。然后你可能有另一个使用
函数的函数,并将测试值传递给它。这允许您根据它正在做的事情来分离代码。

Of course all your code will likely be wrapped in a set of functions/methods that you're using to do the actual calculations. For example you may have a high level function that does the actual calculation. You might then have another function that uses the earlier function and passes test values to it. This allows you to separate out the code based upon what it is doing.

您的编程类和讲师应该能够向您解释(或已经有)这个。你的编程书也应该有很多例子。

Your programming class and instructor should be able to explain (or already have) this to you. Your programming book should have plenty of examples as well.


这篇关于毕达哥拉斯三重奏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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