connoisseur
Broken In
It's a program for finding the biggest palindrome possible by multiplying two 3-digit numbers.
I'm using Turbo C++ 3.0
However it's showing wrong outputs.
I'm 100% sure that the palindrome code is correct and I checked separately with "123" as input, even then it showed wrong output.
Please check the code for any errors and run it in your compiler.
I'm using Turbo C++ 3.0
However it's showing wrong outputs.
I'm 100% sure that the palindrome code is correct and I checked separately with "123" as input, even then it showed wrong output.
Please check the code for any errors and run it in your compiler.
Code:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,r; // a=num1 b=num2 r=remainder
long int p,cp,np=0; //p=product cp=copy-of-product np=new-product
for(b=999;b>99;b--) //outer-loop
{
for(a=999;a>99;a--) //inner-loop
{
p=a*b; //product
cp=p;
while(cp>0) //palindrome code
{
r=cp%10;
cp=cp/10;
np=(np*10)+r;
}
if(np==p) //if yes, break out of inner-loop
break;
}
if(np==p) //if yes, break out of outer-loop
break;
}
cout<<"num1 = "<<a<<" num2 = "<<b<<" product = "<<p;
}