TheAlgorithms-C/project_euler/problem_4/sol.c

32 lines
542 B
C
Raw Normal View History

2019-10-01 17:21:55 +03:00
#include <stdio.h>
int is_palindromic(unsigned int n)
{
unsigned int reversed = 0, t = n;
while (t>0)
{
reversed = 10 * reversed + (t % 10);
t /= 10;
}
return reversed == n;
}
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;
}