用毕达哥拉斯定理求解直角三角形 [英] Solving right triangle w/Pythagorean theorem

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

问题描述

大家好,我是新来的,我有这个C ++程序,我必须写,但它一直给我没用。这是一个问题:


一个直角三角形的边可以是整数。右三角形边的一组三个整数值称为毕达哥拉斯三元组。这三方必须满足以下关系:

(side1)^ 2 +(side2)^ 2 =(斜边)^ 2

输出side1,side2的所有毕达哥拉斯三元组和斜边都不再是100.


例如:

side1 side2斜边

3 4 5



你必须使用嵌套专用来打印结果。

hi everyone I am new here and I have this C++ program that I have to write but it keep given me nothing useful. here is the question:


A right triangle can have sides that are all integers. A set of three integer values for the sides of a right triangle is called a Pythagorean triple. These three sides must satisfy the following relationship:
(side1)^2 + (side2)^2 = (hypotenuse)^2
Output all Pythagorean triples for side1, side2, and hypotenuse all no longer 100.

For example:
side1 side2 hypotenuse
3 4 5


you have to do it using nested for only and print the result.

展开 | 选择 < span class =codeDivider> | Wrap | 行号

推荐答案

您有什么问题?


您是否尝试过这段代码?
What is your question?

Have you tried this code?


我的问题是我必须为side1和一个循环敌人二写一个循环,并为斜边写一个循环。这三个必须是循环的。当这个等式时必须停止:(side1)^ 2 +(side2)^ 2 =(斜边)^ 2

被找到并且打印所有side1,side2和斜边。我尝试了这段代码,但它给了我一个无限循环。

有人可以帮忙吗?

谢谢
my question is that I have to write a loop for side1 and a loop foe side two and a loop for the hypotenuse. and the three must be for loop. the must stopes when this equation: (side1)^2 + (side2)^2 = (hypotenuse)^2
is found and the print all side1,side2 and hypotenuse. i tried this code but it gives me an infinite loop.
can anyone help?
thank you


该代码中的任何内容都不会给你一个无限循环 - 它只需要很长时间时间执行。你可以做的一件事就是缩短这个时间是移除最外面的循环(我控制它的那个循环),因为这对你的代码没有任何贡献,但是将执行的执行次数增加到100次。但是,你的代码正在做100 * 100 * 100 = 1,000,000次执行,所以在决定它是无限循环之前给它一些时间。
Nothing in that code should give you an infinite loop - it simply takes a very long time to execute. One thing you can do to shorten this time is to remove the outermost loop (the one with i controlling it), as this contributes nothing to your code, but multiplies the executions done by 100. Still, your code is doing 100 * 100 * 100 = 1,000,000 executions, so give it some time before deciding it''s an infinite loop.


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

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