Palindrome2 loop not working
<p>In the program I am pasting the palindrome2 function is not working correctly in the loop as max2 is giving the output 998000(upper limit of for loop) whereas for an individual number '1441' its working just fine and giving the output as 1.Can you please guide???</p>

<pre><code>#include &lt;iostream&gt;
long palindrome1(long);
long palindrome2(long);

int main()
{
    using namespace std;
    long a,b=111,max1=0,max2=0;
    for(b=111;b&lt;998001;b++)
    {
      if((palindrome2(b))==1)
      {
          max2=b;
      }
    }
    for(a=11;a&lt;998001;a++)
    {
        if((palindrome2(a))==1)
        {
          max1=a;
        }
    }
     cout&lt;&lt;max1&lt;&lt;endl;
     cout&lt;&lt;max2&lt;&lt;endl;
     cout&lt;&lt;palindrome2(1441)&lt;&lt;endl;
     cin.clear();
     cin.get();
}
long palindrome2(long n)
{
    long a[6],b,c=0;
    do {
        a[c]=n%10;
        n=n/10;
        c++;
    } while(n&gt;0);

    b=c;
    if(b%2!=0)
    {
        for(int l=b/2;l&gt;=0;l--)
            for(int m=(b/2)+1;m&lt;=b;m++)
            {
                if(a[l]!=a[m])
                {
                    return 0;
                    break;
                }
            }
    }
    else
    {
        return 1;   
    }
}

long palindrome1(long n)
{
    long a[6],b,c=0;
    do {
        a[c]=n%10;
        n=n/10;
        c++;
    } while(n&gt;0);

    b=c;
    if(b%2==0)
    {
        for(int k=(b/2)-1;k&gt;=0;k--)
            for(int d=((b/2)+1);d&lt;=b;d++)
            {
                if(a[k]==a[d])
                {
                    return 0;
                    break;
                }
            }
    }
    else
    {
        return 1;   
    }
}
</code></pre>
