Programming/C#2011. 10. 19. 02:01
.. too boring that's why I made this.

Actually, there are a lot of easier ways than the way that I did
I only use one library method, which is Math.pow

Here is the source code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    public class Point
    {
        public static void Main()
        {
            for (int i = 0; i < 30000; i++)
            {
                if (Palindromic(i))
                    Console.WriteLine(i);
            }
        }

       public static bool Palindromic(int n)
       {
           // get how many digit we have
           //
           //int temp = n;
           int i;
           int temp;
           int digit = 0;
           for(temp = n;temp>0;digit++)  // get the number of digits.
           {
               temp /= 10;   
           }


           int firstDigit = 0;
           int secondDigit = 0;

           for(i=0;i<(digit/2);i++)
           {
               firstDigit = (n / (int)Math.Pow(10,i)) % 10;
               secondDigit = (n / (int)Math.Pow(10,digit-(i+1))) % 10;
               if(firstDigit != secondDigit)
                   break;
           }
           if (i == (digit / 2))
               return true;
           return false;
           
       }
           
    }
}

'Programming > C#' 카테고리의 다른 글

How to shutdown a computer in c#  (0) 2011.12.25
Posted by 박세범