Answers for "efficient way to find palindrome cpp"

C++
1

check if a string is palindrome cpp

// Check whether the string is a palindrome or not.
#include <bits/stdc++.h>

using namespace std;

int main(){
    string s;
    cin >> s;
    
    int l = 0;
    int h = s.length()-1;

    while(h > l){
        if(s[l++] != s[h--]){
            cout << "Not a palindrome" << endl;
            return 0;
        }
    }
    cout << "Is a palindrome" << endl;
    return 0;

}
Posted by: Guest on January-23-2021
0

c++ palindrome checker

#include <iostream>
using namespace std;

bool isPalindrome(int x) {
    int rem,reverse=0;
    while(x!=0){    
        rem=x%10;      
        reverse=reverse*10+rem;    
        x/=10;
        if (x == reverse) return true;
        else return false;
    }
    return true;
}

int main() {
    int n;
    cin >>n;
    
    if(isPalindrome(n)) {
        cout <<n<<" is a palindrome";
    }
    else {
        cout << n<<" is NOT a palindrome";
    }
    return 0;
}
Posted by: Guest on October-05-2021

Code answers related to "efficient way to find palindrome cpp"

Browse Popular Code Answers by Language