Example #1
0
        public static string problem9_1()
        {
            List<Triangle> possibleTriangles = new List<Triangle>();
            Triangle answer = new Triangle();
            for (int a = 1; a < 995; a++)
            {
                for (int b = a + 1; b < 996; b++)
                {
                    for (int c = b + 1; c < 997; c++)
                    {
                        if (a + b + c == 1000)
                            possibleTriangles.Add(new Triangle(a, b, c));
                    }
                }
            }

            foreach (Triangle triange in possibleTriangles)
            {
                if (triange.IsPythagoreanTriplet())
                {
                    answer = triange;
                    break;
                }
            }

            return string.Format("{0}a = {2}{1}{0}b = {3}{0}c = {4}{0}{1}a*b*c = {5}",
                " ", Environment.NewLine, answer.SideA, answer.SideB, answer.SideC, answer.ProductOfSides());
        }