/
problem_004.c
36 lines (30 loc) · 911 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
// -*- compile-command: "gcc -std=c99 -o problem_004 problem_004.c ceuler.c -Wall -lm" -*-
// Copyright (c) 2014 Michael Caldwell
#include <stdio.h>
#include "ceuler.h"
int main()
{
printf("Project Euler - Problem 4:\n"
"Find the largest palindrome made from the product of two 3-digit numbers.\n\n");
// Begin time tracking
struct timeval start;
gettimeofday(&start, NULL);
int maxPalindrome = 0;
for (int num1=100 ; num1<1000 ; num1++)
{
for (int num2=num1 ; num2<1000 ; num2++)
{
int product = num1 * num2;
if (isPalindromic(product) == true)
{
if ( product > maxPalindrome)
{
maxPalindrome = product;
}
}
}
}
printf("Largest palindromic product: %d\n", maxPalindrome);
printElapsedTime(start);
return 0;
}