2020-06-05 19:20:25 +03:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* \brief [Problem 4](https://projecteuler.net/problem=4) solution
|
|
|
|
*/
|
2019-10-01 17:21:55 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2020-06-05 19:20:25 +03:00
|
|
|
/** Check if number is palindromic
|
|
|
|
* \param[in] n number to check
|
|
|
|
* \returns 1 if palindromic
|
|
|
|
* \returns 0 if not palindromic
|
|
|
|
*/
|
2019-10-01 17:21:55 +03:00
|
|
|
int is_palindromic(unsigned int n)
|
|
|
|
{
|
|
|
|
unsigned int reversed = 0, t = n;
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
while (t > 0)
|
2019-10-01 17:21:55 +03:00
|
|
|
{
|
|
|
|
reversed = 10 * reversed + (t % 10);
|
|
|
|
t /= 10;
|
|
|
|
}
|
|
|
|
return reversed == n;
|
|
|
|
}
|
|
|
|
|
2020-06-05 19:20:25 +03:00
|
|
|
/** Main function */
|
2019-10-01 17:21:55 +03:00
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
unsigned int i, j, max = 0;
|
|
|
|
for (i = 100; i <= 999; i++)
|
|
|
|
{
|
|
|
|
for (j = 100; j <= 999; j++)
|
|
|
|
{
|
|
|
|
unsigned int p = i * j;
|
|
|
|
if (is_palindromic(p) && p > max)
|
|
|
|
{
|
|
|
|
max = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("%u\n", max);
|
|
|
|
return 0;
|
|
|
|
}
|