check wheather string is palindrome or not code example
Example 1: Write a function that tests whether a string is a palindrome
def palindrome_check(string):
string = list(string)
tmp = []
for x in range(0, len(string)):
if(string[x] != " "):
tmp.append(string[x].lower())
array1 = []
i = 0
j = len(tmp)-1
while(i < len(tmp)):
array1.append(tmp[j])
i += 1
j -= 1
counter = 0
for x in range(0, len(tmp)):
if(tmp[x] == array1[x]):
counter += 1
if(counter == len(tmp)):
return True
return False
Example 2: Write a program to check whether inputted string is palindrome or not.
int main()
{
char s[1000];
int i,n,c=0;
printf("Enter the string : ");
gets(s);
n=strlen(s);
for(i=0;i<n/2;i++)
{
if(s[i]==s[n-i-1])
c++;
}
if(c==i)
printf("string is palindrome");
else
printf("string is not palindrome");
return 0;
}