C++ palindrome checker – C++ Program to Check whether a string is Palindrome or Not

C++ palindrome checker: In the previous article, we have discussed C++ Program to Count Number of Vowels, Consonant, and Spaces in String. In this article, we will see C++ Program to Check whether a string is Palindrome or Not.

C++ Program to Check whether a string is Palindrome or Not

C++ Program to Check whether a string is Palindrome or Not

#include <iostream>
 
using namespace std;
  
int main(){
    char inputString[100];
    int l, r, length = 0;
    cout << "Enter a string for palindrome check\n";
    cin >> inputString;
     
    // Find length of string
    while(inputString[length] != '\0')
        length++;
          
    // Initialize l(left) and r(right) to first and 
    // last character of input string 
    l = 0;
    r = length -1;
    // Compare left and right characters, If equal then 
    // continue otherwise not a palindrome
    while(l < r){
        if(inputString[l] != inputString[r]){
            cout<<"Not a Palindrome"<< endl;
            return 0;
        }
        l++;
        r--;
    }
    cout << "Palindrome\n" << endl;
     
    return 0;
}

Output

Enter a string for palindrome check
MADAM
Palindrome
Enter a string for palindrome check
APPLE
Not a Palindrome

C++ is a powerful general-purpose programming language. It is mostly used to develop browsers, operating systems, games and so on. Beginners who want to know more inversions of C++ language can learn the Basic C++ Programs for a better and quick understanding of the coding.