Created
November 9, 2014 10:06
-
-
Save Dinner1111/83ffde840754154bde3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace ProjectEuler | |
{ | |
class Problem_9 | |
{ | |
/* | |
* A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, | |
* | |
* a^2 + b^2 = c^2 | |
* For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2. | |
* | |
* There exists exactly one Pythagorean triplet for which a + b + c = 1000. | |
* Find the product a * b * c | |
*/ | |
public static void Run() | |
{ | |
int sum = 0; | |
int product = 0; | |
int a = 3, b = 4, c = 5; | |
for (int multiplier = 2; sum != 1000; multiplier++) | |
{ | |
sum = a + b + c; | |
if (sum == 1000) | |
product = a * b * c; | |
a *= multiplier; | |
b *= multiplier; | |
c *= multiplier; | |
} | |
Console.WriteLine(product); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment