Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Write a function that is called this way:
>> n = palin_product(dig,lim);
The function returns the largest palindrome smaller than lim that is the product of two dig digit numbers. If no such number exists, the function returns 0.

What I have tried:

MAths involved -
if 3 is entered as dig then 999*999 we can get the lim.Palindrome can be found out by converting number to string and then check if the string is equal to its reverse. I am stuck on how to check that the number is a product of 2 numbers.
Posted
Updated 9-Dec-16 1:14am

1 solution

 
Share this answer
 
Comments
Member 12895794 9-Dec-16 8:03am    
I know how to factor a number. I don't know how to check in code.
OriginalGriff 9-Dec-16 8:21am    
If you know how to factor on paper, then you can apply the same algorithm in code.
Give it a try! It's probably a lot easier than you think.
Member 12895794 9-Dec-16 8:55am    
the rest of my thinking is correct?
OriginalGriff 9-Dec-16 9:17am    
:laugh:
How would I know? I can't read your mind, and you haven't told us the rest of your thinking!
The string technique for palindromes has the advantage of being easy to do, if not particularly efficient. OK for one-offs, but a big drain on resources if you want to check a lot of numbers. You could do it with modulus and divide to reverse the number. Once reversed, if the two integers are the same it's a palindrome.
Member 12895794 9-Dec-16 9:24am    
Thanx for your help Man! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900