-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem_004.c
37 lines (35 loc) · 859 Bytes
/
Problem_004.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int straightProduct;
int product;
int nonStraightProduct;
int number;
int max;
max = 0;
for(int i = 999; i >= 0; i--) //I do countdown from 999 because we need the LARGEST palindrome product.
{
for(int k = 999; k >= 0; k--)
{
straightProduct = i * k;
product = straightProduct;
nonStraightProduct = 0;
while(product != 0)
{
number = product % 10; //I take the last digit of the product.
nonStraightProduct = nonStraightProduct * 10 + number; //I add it as the first digit of the nonStraightProduct.
product = product/10; //I remove the last digit, because I don't need it anymore.
}
if(straightProduct == nonStraightProduct)
{
if(straightProduct > max)
{
max = straightProduct;
}
}
}
}
printf("MaX:%d\n", max);
return 1;
}