Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (anonymous):

Write a C++ program to find all the pythagorean triplets in the range 1-1000..Please help me guys.!!!

OpenStudy (mandre):

What have you got so far?

OpenStudy (anonymous):

\[a^2 +b^2 = c^2\] go through the range for a and b and check if \[\sqrt{a^2 +b^2}\] is an integer

OpenStudy (anonymous):

So, how many loops will I need for this? just one?

OpenStudy (anonymous):

If you use brute force, you'd need to the a and b values and see if the resulting c_squared is a perfect square and c_squared<1 000 000 There is lot's of math theory on this See http://en.wikipedia.org/wiki/Pythagorean_triple http://mathworld.wolfram.com/PythagoreanTriple.html http://en.wikipedia.org/wiki/Formulas_for_generating_Pythagorean_triples A solutions up to c = 2100 http://www.tsm-resources.com/alists/trip.html Here is a problem on a specific triplet that might help you somewhat http://www.mathblog.dk/pythagorean-triplets/

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!