471,071 Members | 1,331 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

using a triple-nested for...next loop

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.
Oct 18 '06 #1
5 5067
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.
Oct 18 '06 #2
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.

Oct 18 '06 #3
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:
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.
Oct 18 '06 #4
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.
Oct 18 '06 #5
I was not looking for the answers, just direction. Thanks to those of you who
responded to this message with direction.

"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.
>
>

Oct 18 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by S Manohar | last post: by
3 posts views Thread by Anthony Roberts | last post: by
1 post views Thread by Edward C. Jones | last post: by
8 posts views Thread by Christoph Zwerschke | last post: by
11 posts views Thread by bearophile | last post: by
14 posts views Thread by dmh2000 | last post: by
8 posts views Thread by Lawrence D'Oliveiro | last post: by
gchq
2 posts views Thread by gchq | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.