Problem 4

Statement
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99.

Find the largest palindrome made from the product of two 3-digit numbers.

Solution
The code, in C.

#include <stdio.h>

int palindrome(int n){
  int i,j,k=10,l=10,a,b,t,c=0;
  for(a=1;a<n;a++)
    k*=10;
  for(a=1;a<n-1;a++)
    l*=10;
  for(i=l;i<k;i++)
    for(j=l;j<k;j++){
      a=t=i*j;
      b=0;
      while(t!=0){
	b*=10;
	b+=t%10;
	t/=10;
      }
      if(b==a &amp;amp;amp;&amp;amp;amp; a>c) c=a;
    }
  return c;
}

int main(void){
  printf("%d\n",palindrome(3));
  return 0;
}

Answer
906609

No tags for this post.

SPEAK / ADD YOUR COMMENT
Comments are moderated.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>