Created
January 14, 2014 08:09
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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