answersLogoWhite

0

#include <math.h>

// this will test if a base 10 integer is a palindrome

int is_palindrome_10(const unsigned int n) {

if( n < 10 ) return 1;

unsigned int i, num_digits, num_digits_2;

num_digits = ((unsigned int) log10(n) + 1);

num_digits_2 = num_digits/2;

// sorry the if statement is so ugly. looks neater in my editor :\

for(i = 0; i < num_digits_2; ++i)

if( ((unsigned int) ( n/pow(10, num_digits - i - 1) ) % 10) != ((unsigned int) ( n/pow(10, i) ) % 10) )

return 0;

return 1;

}

User Avatar

Wiki User

16y ago

What else can I help you with?

Related Questions

Program for palindrome in php?

You could use a function like this:function isPalindrome($string) {$string = strtolower($string);return (strrev($string) == $string) ? true : false;}and then to check a palindrome call an if statement like so:if(isPalindrome($test)) {echo $test.' is a palindrome';}else {echo $test.' is not a palindrome';}


What is an example program in Bluej whether a number is a palindrome or not?

class test { public static void main(int num) { int num2=num; int rnum=0; while (num2&gt;0) { int q=num2/10; int dig=num2%10; rnum = rnum*10+dig; num2=q; } if (rnum==num) System.out.println("Palindrome number"); else System.out.println("Not a Palindrome number"); } }


How do you test whether 7 is a factor of 291?

Divide 7 into 291. If the result is an integer, 7 is a factor.


How would you test to see whether 7 is a factor of 29?

Divide 7 into 29. If the answer is an integer with no remainder, it's a factor.


How do you write c program to test that an integer number is divisible by 2?

int isDivisibleByTwo(int N) return N % 2 == 0;


Can you do a boolean test on integer in java?

No


What are some examples of palindrome programs using letters and numbers?

When working with letters we must work with strings (character arrays). To determine if a string is a palindrome we use two pointers, one for each end of the string. So long as the characters pointed to are the same, we advance the pointers one character inwards. If the characters pointed at differ, the string is not a palindrome and we can stop checking. When the pointers meet or pass each other, the string must be a palindrome so we can stop checking. Note that the string must be composed entirely of letters of the same case (typically lower-case). All punctuation and word-spacing must also be removed since we're only interested in the letters. We achieve this by copying the string and manipulating the copy, leaving the original string intact. When working with integers, we simply reverse the digits and test to see if it is equal to the original integer. We achieve this by repeatedly dividing the integer by 10 and taking the remainder to extract each digit: Algorithm: reverse_integer Input: a positive integer, n Output: the integer reversed r = 0 repeat while n &gt; 0 m = n % 10 // % = modulo (remainder after division by 10) r = r * 10 + m n = n / 10 end repeat return r A less efficient method is to convert the number to a string and then test the string. A real number is a palindrome when there are as many digits before the decimal point as there are after it, and the integer component is the reverse of the fractional component. We can test this by taking the integer component and reversing it using the algorithm above. We then convert back to a real number and divide by 10 until the number is less than 1. We than add on the original integer component and compare with the original real number. If they are equal, the real number is a palindrome.


Write a shell program using if-the-else to test whether a variable name is a directory or a file?

see : Write_a_shell_program_using_the_if-the-else_to_test_whether_a_variable_name_is_a_directory_or_a_file


Does 14 go into 48 evenly?

14 does not go into 48 evenly. To test whether it does, you can divide 48 by 14. If your answer is an integer (ex. 1, 2, 3, etc..) it can go into it evenly. 48/14=3.24857 Since the answer isn't an integer, 14 does not go into 48 evenly.


Write a program in c that prompt user with following lines add two integers test an integer for odd or even and quit?

write a program in C that prompts the user with the following lines: a) Add two integers c) Compare two integers for the larger t) Test an integers for odd or even q) Quit


How do you determine whether a no is prime or not?

A prime number is a positive integer with two factors: one and the number itself. If you test the numbers up to the square root and your number is not divisible by any of them, it's prime.


The test of an entrepreneurial decision is whether or not?

The test is whether or not the decision results in a profit.