mituri

[C++] najwiekszy iloczyn palindromow

Oct 1st, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. /*
  2. Project Euler("https://projecteuler.net/archives")
  3. Problem 4
  4. A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
  5. Find the largest palindrome made from the product of two 3-digit numbers.
  6. */
  7.  
  8. int main(){
  9. int size = 1000; long product = 0, max = 0;
  10. char buffer[10];
  11.  
  12. for(int i = 0 ; i < size; i ++){
  13. for(int j = 0; j < size; j++){
  14. product = i * j;
  15. _itoa_s(product, buffer,10);
  16.  
  17. if(buffer[0] == buffer[5] && buffer[1] == buffer[4] && buffer[2] == buffer[3]){
  18. if(max < product) max = product;
  19. }
  20. }
  21. }
  22. cout << max << endl;
  23. system("PAUSE");
  24. }
Advertisement
Add Comment
Please, Sign In to add comment