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?