| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #include <stdio.h>
- #include <stdint.h>
- #include <stdbool.h>
- bool ispalindrome(const char *cstr, uint64_t cstr_size);
- int
- main(int argc, const char **argv)
- {
- uint64_t res = 0;
- uint64_t sum = 0;
- uint64_t upper_limit = 999;
- uint64_t n1 = upper_limit, n2 = upper_limit;
- char str[16] = {0};
- uint64_t str_size = 0;
- while ( n2 > 0 ) {
- sum = n1 * n2;
- str_size = (uint64_t)sprintf(str, "%ld", sum);
- if ( ispalindrome(str, str_size) ) {
- if ( sum > res ) {
- res = sum;
- }
- }
- n1 -= ( n1 > 0 );
- if ( n1 == 0 ) {
- n1 = upper_limit;
- --n2;
- }
- }
- printf("Result = %ld!\n", res);
- (void) argc; (void) argv;
- return 0;
- }
- bool
- ispalindrome(const char *cstr, uint64_t cstr_size)
- {
- uint64_t ptr_start = 0;
- uint64_t ptr_end = cstr_size-1;
- while ( ptr_start < ptr_end ) {
- if ( cstr[ptr_start] != cstr[ptr_end] ) {
- return false;
- }
- ++ptr_start;
- --ptr_end;
- }
- return true;
- }
|