c - Project Euler 4 - 5 digits palindrome -
I have to solve problem 4 on Project Oller site for my homework:
The biggest palladium Product
reads a pulindromic number both ways. <2 p>
Find the largest pandidome made from two 3-digit numbers product.
# include & lt; Stdio.h & gt; Int main () {int i, j, palindrome [1000], n, temp, k = 0, num [10], max, digits; For (i = 999; i> = 320; i--) {for (j = 999; j> = 320; j--) {n = i * j; Temporary = n; Number = 0; {Num [points] = do the temporary% 10; Temporary / = 10; Issue ++; } While (temporary! = 0); If (num [0] == number [5] and amp; amp [1] == number [4] & amp; [2] == number [3]) {palindrome [k] = n; K ++; }}} Max = palindrome [0]; {If (palindrome [i]> gt; = max) max = palindrome [i]; for i (i = 1; i & lt; k; i ++); } Printf ("% d \ n", max); } I have got the correct answer, but my code works only for numbers with 6 digits and it is 100 * 100 (10000, 5 digits) to 999 * 99 ( 998001, 6 digits).
Check my code from 320 * 320 to 999 * 99.
So can it be repaired to work with 5 points or should I leave it like this?
Change the internal loop to test the digit / 2
with number [10] , the number of digits can be 1 to 10.
// As is good for at least _ 32k, use long / longest at least _ 2 m long N = (tall) I * J is good; Tall temp = n; Do {...} while (temp! = 0); Boole is only true; (Int a = 0; a & lt; num; 2; a ++) {if (num [a]! Num = numeral [1 mark -a]) same = wrong; } If (a) {palindrome [k] = n; K ++; }
Comments
Post a Comment