Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //A palindromic number reads the same backwards.The largest palindrome made from the product of 2 2 digit nos is 9009 = 91 × 99.
- //Find the largest palindrome made from the product of two 3 - digit numbers.
- #include <iostream>
- #include <cmath>
- using namespace std;
- int digitCounter(int x)
- {
- int digitCount = 0;
- while (x != 0)
- {
- x /= 10;
- digitCount++;
- }
- return digitCount;
- }
- double digitCountInterpreter(int y)
- {
- double digitCountInterpreted = pow(10, (y - 1));
- return digitCountInterpreted;
- }
- double reverser(int z)
- {
- int logCounter=1;
- double reverse = 0;
- int fix = z;
- while (z != 0)
- {
- reverse += ((z % 10) * ((digitCountInterpreter(digitCounter(fix)))/logCounter));
- z /= 10;
- logCounter *= 10;
- }
- return reverse;
- }
- bool palindrome(int num)
- {
- if (num == reverser(num)) return true;
- return false;
- }
- bool productOf2ThreeDigitNums(int n)
- {
- int int1 = 100, int2 = 100;
- while (int1 < 1000)
- {
- if (n == int1*int2) return true;
- else
- if (int2 != 999) int2++; else
- {
- int1++;
- int2 = 100;
- }
- }
- return false;
- }
- int main()
- {
- for (int h = 10000; h < 1000000; h++)
- if ((palindrome(h) == true) && (productOf2ThreeDigitNums(h) == true)) cout << h << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement