problem4
地址:https://projecteuler.net/problem=4。
源码:git@code.aliyun.com:c-program/projecteuler.gitt。
问题:找到三位数相乘最大回文数。
#include <stdio.h>#include <math.h>#include "debug.h"#define BIT 3int isPalindrome(const long int number){ char tmp[BIT * 2] = ""; int i = 0; int lth = sprintf(tmp, "%ld", number) - 1; while (i < lth - i){ if (tmp[i] != tmp[lth - i]) return 0; i++; } return 1;}int main(int argc, char **argv){ int iMin = pow(10, BIT - 1); int iMax = pow(10, BIT); long int iResult = 0; int i, j; long int tmpResult = 0; debugTime(); for (i = iMax - 1; i > iMin; i--){ for (j = i; j > iMin; j--){ tmpResult = i * j; if (isPalindrome(tmpResult) && (iResult < tmpResult)){ iResult = tmpResult; break; } } } printf("Problem4 Answer: %ld\n", iResult); debugTime(); return 0;}