Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- int isPalindrome(int n);
- int main(void)
- {
- /*
- int x, y, prod, pal = 0;
- for (x = 100; x < 1000; x++)
- for (y = 100; y < 1000; y++) {
- prod = x * y;
- if (isPalindrome(prod) && prod > pal)
- pal = prold;
- }
- printf("Largest Palindrome: %d\n", pal);
- */
- int x = 65356;
- printf("%d\n", isPalindrom(x));
- }
- int isPalindrome(int n)
- {
- int firstDigit = n % 10, lastDigit;
- int ncopy = n, numDigits = 0;
- do
- {
- lastDigit = ncopy;
- numDigits++;
- } while((ncopy /= 10) > 0);
- if (firstDigit == lastDigit)
- {
- if (numDigits <= 2)
- return 1;
- // This line has major issues!!!
- n = (n - lastDigit * ((int) pow(10, numDigits))) /10;
- return isPalindrome(n);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement