Explanation
In this program, we need to check whether a given string is palindrome or not.
Kayak
A string is said to be palindrome if it reads the same backward as forward. For e.g. above string is a palindrome because if we try to read it from backward, it is same as forward. One of the approach to check this is iterate through the string till middle of string and compare a character from back and forth.
Algorithm
- Define a string.
- Define a variable flag and set it to true.
- Convert the string to lowercase to make the comparison case-insensitive.
- Now, iterate through the string forward and backward, compare one character at a time till middle of the string is reached.
- If any of the character doesn't match, set the flag to false and break the loop.
- At the end of the loop, if flag is true, it signifies string is a palindrome.
- If flag is false, then string is not a palindrome.
Input:
string = "Kayak"
Output:
Given string is palindrome.
Python
Output:
C
Output:
JAVA
Output:
C#
Output:
PHP
Output: