Skip to content

Instantly share code, notes, and snippets.

@lindslev
Created January 14, 2014 08:09
Show Gist options
  • Select an option

  • Save lindslev/8414829 to your computer and use it in GitHub Desktop.

Select an option

Save lindslev/8414829 to your computer and use it in GitHub Desktop.
This is my solution to problem 4 on Project Euler : Find the largest palindrome made from the product of two 3-digit numbers.
#include <stdio.h>
int main() {
int i, a, b, c;
int j = 999;
int placeholder = 0;
int face = 0;
int count = 0;
int array[200];
int length = 0;
int test=0;
for(j=999; j>=900; j--) {
for (i=900; i<=999; i++) {
placeholder = i*j;
face = i*j;
length = getlength(placeholder);
for (a = length - 1; a >= 0; a--) {
array[a] = placeholder % 10;
placeholder /= 10;
}
if(array[0] == array[length-1]){
if(array[(length)-(length-1)] == array[length-2]){
if(array[(length)-(length-2)] == array[length-3]){
printf("This should output a potential palindrome %d \n", face);
printf("If so, i: %d, j: %d \n", i, j);
}
}
}
}
}
return 0;
}
int getlength (int value) {
int l=1;
while(value > 9) {
l++;
value /= 10;
}
return l;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment