Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Solving Special Pythagorean Triplet (Euler Problem 9 solution)
WhatsApp
Gaurav Katara
Mar 23
2015
2.4
k
0
0
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a2 + b2 = c2 For example, 32 + 42 = 9 + 16 = 25 = 52. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.
/*
put this code snippet within script and call find Triplet function on body onload.
*/
var
sum = 1000;
var
a;
var
product = 0;
function
findTriplet() {
//finding triplet product
for
(a = 1; a <= sum / 3; a++) {
var
b;
for
(b = a + 1; b <= sum / 2; b++) {
var
c = sum - a - b;
if
(c > 0 && (a * a + b * b == c * c)) {
alert(a +
' '
+ b +
' '
+ c);
product = (a b c);
}
}
}
alert(product);
}
pythagorean triplet
euler project
euler problem 9
Up Next
Solving Special Pythagorean Triplet (Euler Problem 9 solution)