C# Implementation of Problem 9
View source code here on GitHub!
1/*
2Project Euler Problem 9
3
4
5
6Problem:
7
8A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
9a**2 + b**2 = c**2
10
11For example, 3**2 + 4**2 = 9 + 16 = 25 = 5**2.
12
13There exists exactly one Pythagorean triplet for which a + b + c = 1000.
14Find the product abc.
15*/
16using System;
17
18namespace Euler
19{
20 public class p0009 : IEuler
21 {
22 public object Answer()
23 {
24 for (uint c = 3; ; c++)
25 {
26 uint c_square = c * c;
27 for (uint b = 2; b < c; b++)
28 {
29 uint b_square = b * b;
30 for (uint a = 1; a < b; a++)
31 {
32 uint a_square = a * a;
33 if (a_square + b_square == c_square && a + b + c == 1000)
34 return (int)(a * b * c);
35 }
36 }
37 }
38 }
39 }
40}