bhalash

Project Euler problem #4 solution.

Jun 1st, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.44 KB | None | 0 0
  1. using System;
  2.  
  3. public class Problem
  4. {
  5.     static void Main()
  6.     {
  7.         int a = 0;
  8.         int b = -1;
  9.  
  10.         for (int i = 999; i >= 100; i--)
  11.         {
  12.             for (int j = 999; j >= 100; j--)
  13.             {
  14.                 a = i * j;
  15.  
  16.                 if ((a == Reverse(a)) && (a > b))
  17.                     b = a;
  18.             }
  19.         }
  20.  
  21.         Console.WriteLine("\n{0}\n", b);
  22.     }
  23.  
  24.     static int Reverse(int x)
  25.     {
  26.         int y = 0;
  27.  
  28.         while (x != 0)
  29.         {
  30.             y *= 10;
  31.             y += x % 10;
  32.             x /= 10;
  33.         }
  34.  
  35.         return y;
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment