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

Here is a 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

Recommended Posts
C++ Program to Convert Uppercase to Lowercase Characters
C++ Program to Count Words in Sentence
C++ Program to Delete a Word from Sentence
C++ Program to Print Array in Reverse Order
C++ Program to Delete Spaces from String or Sentence
C++ Program to Delete Vowels Characters from String
C++ Program to Find Power of Number using Recursion
C++ Program to Check Prime Number Using Function
C++ Program to Convert Decimal Number to Octal Number
All C++ Programs