-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path004.cs
More file actions
60 lines (51 loc) · 1.45 KB
/
Copy path004.cs
File metadata and controls
60 lines (51 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//Largest palindrome product
//Problem 4
//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.
namespace _004
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(findLargePal());
}
static double findLargePal()
{
double large = 0;
for (double x = 999; x > 1; x--)
{
for (double y = 999; y > 1; y--)
{
double z = x * y;
if (isPal(z))
{
if (z > large)
large = z;
}
}
}
return large;
}
static bool isPal(double z)
{
int length = z.ToString().Length;
for (int x = 0; x <= (length / 2); x++)
{
if (getDigit(z, x) != getDigit(z, (length - x - 1)))
return false;
}
return true;
}
static double getDigit(double value ,int position)
{
string number = value.ToString();
return number[position] - 48;
}
}
}