showing results for - "check if palindrome"
Bryn
12 Feb 2020
1#include <stdio.h>
2#include <string.h>
3int main()
4{
5
6     char str[80];
7     int length;
8     printf("\nEnter a string to check if it's a palindrome: ");
9     scanf("%s", str);     // string input
10     length = strlen(str); // finding the string length
11     int i, j, count;
12     for (i = 0, j = length - 1, count = 0; i < length; i++, j--)
13     {
14          // matching string first character with the string last character
15          if (str[i] == str[j])
16          {
17               count++; // if character match, increasing count by one.
18          }
19     }
20     if (count == length) // if count == length, then the string is a palindrome.
21     {
22          printf("'%s' is a palindrome.\n", str);
23     }
24     else // otherwise the string is not a palindrome.
25     {
26          printf("'%s' is not a palindrome.\n", str);
27     }
28     return 0;
29}
Juan Esteban
14 May 2016
1public class Solution {
2    public bool IsPalindrome(int x) {
3        if(x < 0 || (x % 10 == 0 && x != 0)) {
4            return false;
5        }
6
7        int revertedNumber = 0;
8        while(x > revertedNumber) {
9            revertedNumber = revertedNumber * 10 + x % 10;
10            x /= 10;
11        }
12
13        return x == revertedNumber || x == revertedNumber/10;
14    }
15}
Thiago
25 Feb 2017
1function Palindrome(str) { 
2
3  str = str.replace(/ /g,"").toLowerCase();
4  var compareStr = str.split("").reverse().join("");
5
6  if (compareStr === str) {
7    return true;
8  } 
9  else {
10    return false;
11  } 
12
13}
Jacob
24 Apr 2020
1	bool isPlaindrome(string s)
2	{
3	   int i=0;
4	   int j=s.length()-1;
5	   while(i<j)
6	   {
7	       if(s[i]==s[j])
8	       {i++;
9	   j--;}
10	   else break;
11	   }
12	   if (i==j || i>j) return 1;
13	   else return 0;
14	}
15
Enrico
13 Jun 2018
1function isPalindrome(str) {
2  str = str.toLowerCase();
3  return str === str.split("").reverse().join("");
4}
similar questions
queries leading to this page
check if palindrome