I made this program which had to calculate the Largest Palindrome which being the product of two 3-Digit Numbers.
My Program :

#include <iostream.h>
#include <conio.h>
int reverse(int num)
{
int rev=0,mod;
 while(num)
    {
      mod=num%10;
      num=num/10;
      rev=(rev*10)+mod;
    }
 return(rev);
}

void main()
{
textbackground(WHITE);
textcolor(BLACK);
clrscr();
long a,b,c,r=0,d;

for (a=999 ; a>=100 ; a--)
    {
      for (b=999 ; b>=100 ; b--)
        {
          c=a*b;
          d=c;
          r=reverse(c);
           if(r==d)
           break;
           cout <<"A : " <<a <<"\tB : " <<b <<"\tProduct : " <<c <<endl;
        }
      if(r==d)
      break;
    }
cout <<"Largest Palindrome is : " <<d;
getch();
}

It runs for 1-2 minutes and then suddenly stops without displayin any output.
A little help on whats going wrong?

Output values to see what is happening while the program runs. This can also pinpoint where the error is and what variables have bad values.

Output stops at -
A : 146 B : 479 Product : 69934
Doesn't even check the palindrome condition, I guess :|

Its running perfectly for me.

Output :

A : 995 B : 583 Product 580085 Palindrome

And you need to change your program writing, using iostream.h void main() textbackground(WHITE); etc are not standard.

Your output is not inside the if clause. d variable is competely unnecessary. I do not understand why 33 and 34, which interrupt search prematurely (995 and 583 is not correct answer), you are not doing the maximum finding part.

So many errors with my program --
Thanks alot np and pytony.
I guess the main error is with the memory evaluation...like np said, I use quite extra commands. :P
Still the answer is not correct...will try and correct the program and post it as soon as possible ^
^

Ok here it is...made the necesseray adjustments. Still Not Correct :|

#include <iostream.h>
#include <conio.h>
int reverse(int num)
{
int rev=0,mod;
 while(num)
    {
      mod=num%10;
      num=num/10;
      rev=(rev*10)+mod;
    }
 return(rev);
}

void main()
{
clrscr();
long a,b,c,r=0,d,x=0;

for (a=999 ; a>=100 ; a--)
    {
      for (b=999 ; b>=100 ; b--)
    {
      c=a*b;
      d=c;
      r=reverse(c);
       if(r==d)
        {
         if(x<d)
         x=d;
        }

    }
    }
cout <<"Largest Palindrome is : " <<x;
getch();
}

Ok here it is...made the necesseray adjustments. Still Not Correct :|

you really need to explain what happens when asking for help. Based on this statement we can't tell if
1) you now have compile errors
2) you now have link errors
3) your program crashes
4) it surprisingly prints the words to "Jana Gana Mana"

Every post needs to be explicit. Detail what the problem is, and where you think the error is.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.