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.
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:
Note: You can simplifies the coding :)
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();
- }
No comments:
Post a Comment