GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — project_euler/Problem 4.cpp at master · moophis/project_euler Expand file tree/ Copy pathProblem 4.cppMore file actions 41 lines (40 loc) · 976 Bytes / Copy pathProblem 4.cppFile metadata and controls41 lines (40 loc) · 976 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 /* * A palindromic number reads the same both ways. The largest palindrome * made from the product of two 2-digit numbers is 9009 = 91 * 99. * Find the largest palindrome made from the product of two 3-digit numbers. */ #include <iostream> #include <vector> using namespace std; int main() { int multiplier1,multiplier2,maxPal = 1; for (int i = 100; i < 1000; i++) for (int j = i; j < 1000; j++) { int results = i * j,result = results; bool isPal = true; vector<int> bits; while (results) { bits.push_back(results % 10); results = results / 10; } for (int k = 0; k < bits.size() - 1 - k; k++) if(bits[k] != bits[bits.size() - 1 - k]) { isPal = false; break; } if (isPal) if (result > maxPal) { maxPal = result; multiplier1 = i; multiplier2 = j; } } cout << "The largerst palindromic number is: " << maxPal << " = " << multiplier1 << " * " << multiplier2 << endl; return 0; } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |