Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- /* A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
- Find the largest palindrome made from the product of two 3-digit numbers.
- */
- int main()
- {
- int num = 998001; /* num to count down from, j is the first 3 numbers and k is the next 3 */
- int j = 998;
- int k = 001;
- while (num > 111111){
- if ( (j/100) == (k%10)) { /* this compares the first number of j and the last of k, then the opposite, and then the middle numbers */
- if (k/100 == j%10) {
- if ((j%100)/10 == (k%100)/10){
- printf("%d", num);
- return 0;
- }
- }
- }
- num = num - 999; /* decrement by 999 to brute force every possible answer */
- j = num/1000; /* assigns the numbers new first 3 and last 3 to j and k */
- k = num - (j * 1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement