- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find the largest palindrome number made from the product of two n digit numbers in JavaScript
Let us consider the number 9009. This is a special number in the sense that this is the largest palindrome number that can be formed by multiplying two 2-digit numbers (91 and 99).
We are required to write a JavaScript function that takes a number n (which specifies the number of digits). The function should simply find and return the largest palindrome number that can be formed by the multiplication of two n digit numbers.
Example
Following is the code −
const largestPalindromic = num => { let i, n, m, d, max, sup, limit, number = 0; for (i = 1; i < num; i += 1) { number = 10 * number + 9; }; max = number; sup = 10 * number + 9; const isPalindromic = n => { let p = 0, q = n, r; while (n > 0) { r = n % 10; p = 10 * p + r; n = Math.floor(n / 10); }; return p === q; }; for (n = sup * sup, m = max * max; n > m; n -= 1) { if (isPalindromic(n)) { limit = Math.ceil(Math.sqrt(n)); d = sup; while (d >= limit) { if (n % d === 0 && n / d > max) { return n; } d -= 1; } } }; } console.log(largestPalindromic(3));
Output
Following is the output on console −
906609
- Related Articles
- Product of N with its largest odd digit in C
- Largest product of n contiguous digits of a number in JavaScript
- Largest N digit number divisible by given three numbers in C++
- Largest Palindrome Product in C++
- Largest number less than N with digit sum greater than the digit sum of N in C++
- Return the greatest possible product of n numbers from the array in JavaScript
- JavaScript - Find the smallest n digit number or greater
- Largest Even and Odd N-digit numbers in C++
- Find the sum of the largest 5 -digit number and the smallest 6 -digit number.
- Number of n digit stepping numbers in C++
- Find the difference between the largest 3 digit number and the smallest 6 digit number.
- Find the difference between the largest 8-digit number and the smallest 6-digit number.
- Finding the largest 5 digit number within the input number using JavaScript
- Take two numbers m and n & return two numbers whose sum is n and product m in JavaScript
- Largest even digit number not greater than N in C++

Advertisements