Skip to content

Instantly share code, notes, and snippets.

@Dinner1111
Created November 10, 2014 02:47
Show Gist options
  • Save Dinner1111/d1cd6dcab9e8b48a13a2 to your computer and use it in GitHub Desktop.
Save Dinner1111/d1cd6dcab9e8b48a13a2 to your computer and use it in GitHub Desktop.
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()
{
double sum = 0;
double product = 0;
int a = 3, b = 4, c = 5;
for (int multiplier = 2; sum < 1000; multiplier++)
{
sum = (a * multiplier) + (b * multiplier) + (c * multiplier);
if (sum == 1000)
product = a * b * c;
}
Console.WriteLine(product);
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment