Ask Question
5 November, 01:47

Write the function isPalindrome (txt). This function takes a string as a parameter and returns the Boolean value True if the string is a palindrome, False otherwise. • A string is a palindrome if it is spelled the same both forward and backward. • Sentences can also be palindromes, therefore, punctuation, capitalization, and spaces should be ignored. Numbers should not be ignored • If the user provides an input that is not a string, program should return the Boolean value False

+1
Answers (1)
  1. 5 November, 03:40
    0
    There are several ways to do this, depending on your level of experience and the algorithms you know. Try this one:

    Explanation:

    Assuming you know loops, and string arrays, start with isPalindrome (true). Loop through the string, using a counter to keep track of the index location of the last character compared. So, compare index[0] to index[length - 1] (with 1 being the counter variable). Increase the conter by one. Then compare index[1] to index[len-counter] and so on, keeping in mind that when the index to compare and the counter for matching are the same, you break the loop and return isPalindrome, which should remain true. If you come across one that doesn't match, isPalindrome returns false, and the loop is finished immediately.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write the function isPalindrome (txt). This function takes a string as a parameter and returns the Boolean value True if the string is a ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers