Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Project Euler 4 - Largest Palindrome Product
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
bool isPalindrome(int num);
int main(void)
{
int max = 0;
int num;
for (int i = 999; i >= 100; i--)
{
for (int j = i; j >= 100; j--)
{
num = i*j;
if (isPalindrome(num) && num > max)
{
max = num;
}
}
}
printf("%i\n", max);
}
bool isPalindrome(int num)
{
int reverse = 0;
int n = num;
while (n != 0)
{
reverse *= 10;
reverse += n%10;
n /= 10;
}
if (reverse == num)
return true;
else
return false;
}
@CraigRodrigues

This comment has been minimized.

Copy link
Owner Author

commented Aug 12, 2016

Decided to just straight brute force it assuming it wouldn't actually take that long to run through all the products.

https://projecteuler.net/problem=4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.