ProjectEuler_P4

Question:

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.

 

C Code:

#include <stdio.h>

void IsPalind(int number)
{
  int n = 0;
  int temp = number;
  if(0 == number)
  {
    return 0;
  }
  else
  {
    while(temp > 0)
    {
      n = 10*n + temp%10;
      temp = temp/10;
    }
    if(n == number)
    {
      return 1;
    }
    else
    {
      return 0;
    }
  }
}

int main()
{
  int i = 999,j = 999;
  int max = 0;
  for(i = 999;i > 99;i--)
  {
    for(j = i;j > 99;j--)
    {
      int temp = i*j;
      if(IsPalind(temp) && temp > max)
      {
        max = temp;
      }
    }
  }
  printf("%d is not palindromic number!\n",max);
}

 

Answer:

906609

posted on 2014-04-23 17:22  楠哥1991  阅读(126)  评论(0编辑  收藏  举报

导航