Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int ispalindrome(int test)
  6. {
  7.     char willflip[15];
  8.     char willkeep[15];
  9.  
  10.     int compare;
  11.     //get the integer into a string
  12.     itoa (test, willflip, 10);
  13.     //move the string to something we want untouched
  14.     strcpy(willkeep, willflip);
  15.     //strrev does what you'd think
  16.     strrev (willflip);
  17.     //strcmp returns 0 if equal
  18.     compare = strcmp (willkeep, willflip);
  19.  
  20.     if (compare == 0)
  21.         return 1;
  22.     else
  23.         return 0;
  24.  
  25. }
  26.  
  27. int main()
  28. {
  29.     int largest_palindrome = 0, temp = 0;
  30.     int x, y, total;
  31.  
  32.     for (x = 100; x <=999; x++)
  33.         {
  34.             for (y = 100; y <= 999; y++)
  35.                 {
  36.                     total = x * y;
  37.                     if (ispalindrome(total))
  38.                         {
  39.                             temp = total;
  40.                             if (temp > largest_palindrome)
  41.                                 largest_palindrome = total;
  42.                         }
  43.  
  44.                 }
  45.         }
  46.  
  47.     printf("Largest palindrome is %i", largest_palindrome);
  48.  
  49.     return 0;
  50. }