title: Finding the largest palindrome of the product of two three digit numbers problem
body: <p>So on Project Euler the <a href="http://projecteuler.net/index.php?section=problems&amp;id=4" rel="nofollow noreferrer">Problem 4</a> states the following:</p>
  
  <blockquote>
    <p>A palindromic number reads the same
    both ways. The largest palindrome made
    from the product of two 2-digit
    numbers is 9009 = 91  99.</p>
    
    <p>Find the largest palindrome made from
    the product of two 3-digit numbers.</p>
  </blockquote>
  
  <p>I have tried the following:</p>
  
  <pre><code>    #include &lt;stdio.h&gt;
      #include &lt;stdlib.h&gt;
  
      int check(int result)
      {
          char b[7];
          sprintf(b, "%d", result);
          if (b[0] == b[5] &amp;&amp; b[1] == b[4] &amp;&amp; b[2] == b[3])
          {
              return 1;
          }
          else 
          {
              return 0;
          }
      }
  
      int main () {
          int i;
          int g;
          int final;
          for (i = 999; i &gt; 99; i--)
          {
              for (g = 999; g &gt; 99; g--)
              {
                  if (check(g*i) == 1)
                  {
                      final = g*i;
                      goto here;
                  }
              }
          }
          here:
          printf("%d", final);
  }
  </code></pre>
  
  <p>But, this does not work. Instead of the right answer, I get 580085, which I guess is a palindrome at least, but still not the right answer.</p>
  
  <p>Let me explain my program starting from <code>int main</code>:</p>
  
  <ol>
  <li><code>int i</code> and <code>int g</code> are my multipliers. They are those two three digit numbers.</li>
  <li><code>int final</code> is the number that will store the largest palindrome.</li>
  <li>I start two for loops going to down to get every number possibility.</li>
  <li>I get out of the loop using a goto when the first palindrome is reached(probably should not but, it doesn't effect a small program like this too much).</li>
  <li>The first palindrome should be the biggest one possible since I am counting down from the top.</li>
  </ol>
  
  <p>Let me now explain my check:</p>
  
  <ol>
  <li>First off since these are two three digit numbers multiplying together to determine the size a char would need to be to hold that value I went to a calculator and multiplied 999 * 999 and it ended up being 6 then I need to add one because I found out from one the questions I posted earlier that <code>sprintf</code> puts a <code>\0</code> character at the end.</li>
  <li>Ok, now that I have a char and all, I copied <code>result</code> (which <code>i*g</code> in <code>int main</code>) and put it in <code>char b[7]</code>.</li>
  <li>Then I just checked <code>b</code> to see if it equalled it self with by hard coding each slot I needed to check for.</li>
  <li>Then I returned accordingly, 1 for true, and 2 for false.</li>
  </ol>
  
  <p>This seems perfectly logical to me but, it does not work for some weird reason. Any hints?</p>