sentence with palindrome words 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, reversedN = 0, remainder, originalN;
printf("Enter an integer: ");
scanf("%d", &n);
originalN = n;
while (n != 0) {
remainder = n % 10;
reversedN = reversedN * 10 + remainder;
n /= 10;
}
if (originalN == reversedN)
printf("%d is a palindrome.", originalN);
else
printf("%d is not a palindrome.", originalN);
return 0;
}