A palindrome is a sequence of characters which reads the same backward or forwar
ID: 3825607 • Letter: A
Question
A palindrome is a sequence of characters which reads the same backward or forward, e.g "rotator", "madam" and "1221". Write a function isPalindrome which accepts one input string and returns true if the string is a palindrome and false otherwise. Your function should ignore letter case: "madam" and "Madam" are both palindromes.
The function should return the desired output regardless of the input string size. You are required to use the programming method (loops, conditional statements) to check if the input string is a palindrome. Your solution cannot use any Matlab built-in function that has either "str", "eval", "flip" or "printf" in it (basically any function that would flip the string for you in one line). Here's an example of a function call:
Explanation / Answer
Source code
#include <stdio.h>
#include <string.h>
int main()
{
char input[20];
int first, last, middle, len = 0;
gets(input);
while(input[len] != '')
len++;
last = len -1;
middle = len / 2;
puts(" Palindrome Program");
for(first = 0; first < middle; first++)
{
if(input[first] != input[last])
{
puts(" It is Not a Palindrome");
break;
}
last--;
}
if(first == middle)
puts(" It is a Palindrome");
return 0;
}
--------------------------------------------------------------------------------------------------------------------------------------------
Output
123
Palindrome Program
It is Not a Palindrome
--------------------------------------------------------------------------------------------------------------------------------------------------
1221
Palindrome Program
It is a Palindrome
-------------------------------------------------------------------------------------------------------------------------------------------------
MADAM
Palindrome Program
It is a Palindrome
-----------------------------------------------------------------------------------------------------------------------------------
hello
Palindrome Program
It is Not a Palindrome
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.