Thursday, January 16, 2014

Project Euler Solution using C#: Problem 4: Largest Palindrome Product

Problem:

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers.
My Solution: 


        static void Main(string[] args)         {             int min = 100;             int max = 999;             List<int> list = new List<int>();             int multiplied=0;>             for (int i = min; i < max; i++)             {                 for (int j = min; j < max; j++)                 {                     multiplied = i * j;                     string reversed = new string(multiplied.ToString().ToCharArray().Reverse().ToArray());                     if (reversed == multiplied.ToString())                     {                         list.Add(multiplied);                     }                 }             }             Console.WriteLine("the largest palindrome made from the product of two 3-digit numbers is : " + list.Max());             Console.ReadLine();         }
Note: You can simplifies the coding :)

No comments:

Post a Comment