TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Solving Special Pythagorean Triplet (Euler Problem 9 solution)
Gaurav Katara
Mar 23
2015
Code
2.2
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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