#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;
}
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';}
class test { public static void main(int num) { int num2=num; int rnum=0; while (num2>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"); } }
Divide 7 into 291. If the result is an integer, 7 is a factor.
Divide 7 into 29. If the answer is an integer with no remainder, it's a factor.
int isDivisibleByTwo(int N) return N % 2 == 0;
No
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 > 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.
see : Write_a_shell_program_using_the_if-the-else_to_test_whether_a_variable_name_is_a_directory_or_a_file
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 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
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 is whether or not the decision results in a profit.