#include<iostream>
usingnamespace std;
int res1=0
void palindrome(int mul)
{
int k,res=0,count=0;
int p=mul;
while(mul!=0)
{
k=mul%10;
res=(res*10)+k;
mul=mul/10;
}
if(res==p)
cout<<res<<"is a palindrome:\n"
{
if(res1<res)
res1=res;
}
}
int main()
{
int mul,j;
for(int i=1;i<11;i++)
{
for(j=1;j<12;j++)
{
mul=i*j;
if(mul>10)
palindrome(mul);
}
cout<<"\n";
}
return 0;
}
the above code works for all that i need except for the largest palindrome.
my algorithm is like
1. Product each combination
2. use palindrome function to check the result is palindrome or not if multiplication res is >10 and print the palindrome.
3.here i have to check for the largest number by comparing with the previous number. so i have stored the previous value in res1 variable. and i am comparing the res and res1 variables
according to my logic it checks lastly (88<99) that is true
now the problem is how to print the last vale stored in res variable????
if anybody helps i would be thankful
Either you can make the palindrome function of pair return type, returning the pair <bool,int>, bool 1 means associated int is a palindrome, and make an additional variable in main to store the value
OR
Declare a global variable, and make palindrome function to assign largest palindrome to it, then main can read it at the end
but res1 has the largest palindrome, right?? so after two loops in main, just print value of res1 inside main.
And ur first line says u need palindrome of "product of two digit numbers", not "two digit palindrome", so i and j must vary 10 to 99...
If I'm still not getting you, please tell output format you want.