palindrom definition code example
Example 1: palindrome
function isPalindrome(sometext) {
var replace = /[.,'!?\- \"]/g;
var text = sometext.replace(replace, '').toUpperCase();
for (var i = 0; i < Math.floor(text.length/2) - 1; i++) {
if(text.charAt(i) == text.charAt(text.length - 1 - i)) {
continue;
} else {
return false;
}
}
return true;
}
function isPalindrome(str) {
return str === str.split('').reverse().join('');
}
Example 2: palindrome
#include <stdio.h>
int main() {
int n, rev = 0, remainder, num;
printf("Enter an integer: ");
scanf("%d", &n);
num = n;
for(num = n ; n!=0 ; n/=10)
{
remainder = n%10;
rev = rev*10 + remainder;
}
( (rev == num) ? printf("%d is a palindrome.", num) : printf("%d is not a palindrome.", num) );
return 0;
}