1 Answers
Palindrome Check Program
To check if a given string is a palindrome or not, you can use the following algorithm:
- Declare a function that takes a string as input.
- Reverse the input string.
- Compare the input string with its reversed version.
- If they are the same, the input string is a palindrome.
- Return true if it is a palindrome, false otherwise.
Here is a sample implementation in Python:
def is_palindrome(s): return s == s[::-1] input_string = "madam" if is_palindrome(input_string): print(f"{input_string} is a palindrome") else: print(f"{input_string} is not a palindrome")
With this algorithm, you can easily determine if a given string is a palindrome.
Please login or Register to submit your answer