|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
using a triple-nested for...next loopI have to write a program to find all Pythagorean triples for a right
triangle. I know that the squares of two sides of the triangle must equal the square of the third (longest) side. However, I am not sure how to use a triple-nested for...next loop to try all possibilities. For instance, take a look at these numbers: a 3 5 7 8 9 11 b 4 12 24 15 40 60 c 5 13 25 17 41 61 Notice that in each case "a" squared plus "b" squared is equal to the sum of c squared. My program has to compute such a table by iterating through several combinations of numbers to locate ones that meet this criteria. Any suggestions would be helpful. Is this a homework/school assignment?
Anyways, there are an infinite number of Pythagorean triples, so what other information can you provide us? i.e. Are you given a value for one of the sides? Any of the angles of the triangle (other than the 90 degree)? Or any other useful information? Thanks, Seth Rowe Candace wrote: Show quoteHide quote > I have to write a program to find all Pythagorean triples for a right > triangle. I know that the squares of two sides of the triangle must equal > the square of the third (longest) side. However, I am not sure how to use a > triple-nested for...next loop to try all possibilities. > > For instance, take a look at these numbers: > > a 3 5 7 8 9 11 > b 4 12 24 15 40 60 > c 5 13 25 17 41 61 > > Notice that in each case "a" squared plus "b" squared is equal to the sum of > c squared. My program has to compute such a table by iterating through > several combinations of numbers to locate ones that meet this criteria. > > Any suggestions would be helpful. This is for a class. I have to write the program to find all Pythagorean
triples for side1, side2 and hypotenuse, none larger than 30. And I have been instructed to use a triple-nested For...Next loop that tries all possibilities. Show quoteHide quote "rowe_newsgroups" wrote: > Is this a homework/school assignment? > > Anyways, there are an infinite number of Pythagorean triples, so what > other information can you provide us? i.e. Are you given a value for > one of the sides? Any of the angles of the triangle (other than the 90 > degree)? Or any other useful information? > > Thanks, > > Seth Rowe > > > Candace wrote: > > I have to write a program to find all Pythagorean triples for a right > > triangle. I know that the squares of two sides of the triangle must equal > > the square of the third (longest) side. However, I am not sure how to use a > > triple-nested for...next loop to try all possibilities. > > > > For instance, take a look at these numbers: > > > > a 3 5 7 8 9 11 > > b 4 12 24 15 40 60 > > c 5 13 25 17 41 61 > > > > Notice that in each case "a" squared plus "b" squared is equal to the sum of > > c squared. My program has to compute such a table by iterating through > > several combinations of numbers to locate ones that meet this criteria. > > > > Any suggestions would be helpful. > > Well then, since this is for a class, I won't help you cheat yourself
out of a learning experience. Struggling through a problem now will help you in the future, as you will learn good problem solving skills (that don't include quering newsgroups) that apply to more than just programming. Just try to simplify the problem and take it one step at a time... Thanks, Seth Rowe Candace wrote: Show quoteHide quote > This is for a class. I have to write the program to find all Pythagorean > triples for side1, side2 and hypotenuse, none larger than 30. And I have been > instructed to use a triple-nested For...Next loop that tries all > possibilities. > > "rowe_newsgroups" wrote: > > > Is this a homework/school assignment? > > > > Anyways, there are an infinite number of Pythagorean triples, so what > > other information can you provide us? i.e. Are you given a value for > > one of the sides? Any of the angles of the triangle (other than the 90 > > degree)? Or any other useful information? > > > > Thanks, > > > > Seth Rowe > > > > > > Candace wrote: > > > I have to write a program to find all Pythagorean triples for a right > > > triangle. I know that the squares of two sides of the triangle must equal > > > the square of the third (longest) side. However, I am not sure how to use a > > > triple-nested for...next loop to try all possibilities. > > > > > > For instance, take a look at these numbers: > > > > > > a 3 5 7 8 9 11 > > > b 4 12 24 15 40 60 > > > c 5 13 25 17 41 61 > > > > > > Notice that in each case "a" squared plus "b" squared is equal to the sum of > > > c squared. My program has to compute such a table by iterating through > > > several combinations of numbers to locate ones that meet this criteria. > > > > > > Any suggestions would be helpful. > > > > I was not looking for the answers, just direction. Thanks to those of you who
responded to this message with direction. Show quoteHide quote "rowe_newsgroups" wrote: > Well then, since this is for a class, I won't help you cheat yourself > out of a learning experience. Struggling through a problem now will > help you in the future, as you will learn good problem solving skills > (that don't include quering newsgroups) that apply to more than just > programming. Just try to simplify the problem and take it one step at a > time... > > Thanks, > > Seth Rowe > > > Candace wrote: > > This is for a class. I have to write the program to find all Pythagorean > > triples for side1, side2 and hypotenuse, none larger than 30. And I have been > > instructed to use a triple-nested For...Next loop that tries all > > possibilities. > > > > "rowe_newsgroups" wrote: > > > > > Is this a homework/school assignment? > > > > > > Anyways, there are an infinite number of Pythagorean triples, so what > > > other information can you provide us? i.e. Are you given a value for > > > one of the sides? Any of the angles of the triangle (other than the 90 > > > degree)? Or any other useful information? > > > > > > Thanks, > > > > > > Seth Rowe > > > > > > > > > Candace wrote: > > > > I have to write a program to find all Pythagorean triples for a right > > > > triangle. I know that the squares of two sides of the triangle must equal > > > > the square of the third (longest) side. However, I am not sure how to use a > > > > triple-nested for...next loop to try all possibilities. > > > > > > > > For instance, take a look at these numbers: > > > > > > > > a 3 5 7 8 9 11 > > > > b 4 12 24 15 40 60 > > > > c 5 13 25 17 41 61 > > > > > > > > Notice that in each case "a" squared plus "b" squared is equal to the sum of > > > > c squared. My program has to compute such a table by iterating through > > > > several combinations of numbers to locate ones that meet this criteria. > > > > > > > > Any suggestions would be helpful. > > > > > > > > I suggest a strategy. Do not know if it's the best.
.Make a long list L (hashtable) of squared numbers. For each choice of one squared number q in L ( 2,4,9, .. ) iterate all the squared numbers p less than sqrt(q), and any time r = (q - p) is in the list L add the triple (q, p, r). Let me know if makes sense... -P Candace ha scritto: Show quoteHide quote > I have to write a program to find all Pythagorean triples for a right > triangle. I know that the squares of two sides of the triangle must equal > the square of the third (longest) side. However, I am not sure how to use a > triple-nested for...next loop to try all possibilities. > > For instance, take a look at these numbers: > > a 3 5 7 8 9 11 > b 4 12 24 15 40 60 > c 5 13 25 17 41 61 > > Notice that in each case "a" squared plus "b" squared is equal to the sum of > c squared. My program has to compute such a table by iterating through > several combinations of numbers to locate ones that meet this criteria. > > Any suggestions would be helpful.
Need a tip: How do you streamwrite from two different db tables?
Q: Advice on threads UTF-8 encoding problem On Error Goto Next Loop How to simulate Application.DoEvents in a DLL need help!! Bootstrapping .NET 2.0 Dispose problem/crash with maximized MDI child windows VB2005 - Split Files Visual Basic Programming - Reference to fpPublishLogInTempDir uri - ADVANCED question |
|||||||||||||||||||||||