Write a C++ program to find all the pythagorean triplets in the range 1-1000..Please help me guys.!!!
What have you got so far?
\[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
So, how many loops will I need for this? just one?
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/
Join our real-time social learning platform and learn together with your friends!