Palindrome check(cpp)
suryansh taragi
Posted on November 30, 2023
Description of the Palindrome Checker Code:
Function isPalindrome(const string &word):
Takes a string word as input.
Creates a new string (cleanWord) by removing spaces and converting characters to lowercase for case-insensitive comparison.
Checks if the cleaned word is a palindrome.
Returns true if it is a palindrome, and false otherwise.
Main Function:
Declares a string variable userWord to store user input.
Prompts the user to enter a word.
Calls the isPalindrome function to check if the entered word is a palindrome.
Prints "YES, IT IS PALINDROME" or "NO, IT IS NOT A PALINDROME" based on the result.
Palindrome Check:
Utilizes the isPalindrome function to determine whether the entered word is a palindrome.
Palindrome checking is case-insensitive and ignores spaces.
Input and Output:
Takes user input for a word using cin.
Displays the result of the palindrome check using cout.
Palindrome Checking Logic:
Iterates through the cleaned word from both ends, comparing characters.
Returns false if any pair of characters do not match.
Returns true if all pairs match, confirming a palindrome.
Note:
The code uses a simplified method for checking palindromes, suitable for single-word inputs.
It provides a quick and straightforward way to determine if a word is a palindrome or not.
This code serves as a basic palindrome checker, allowing users to input a word and check whether it reads the same backward as forward, considering case insensitivity and ignoring spaces.
code link click here
Posted on November 30, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.