Skip to content

Instantly share code, notes, and snippets.

@sudheesh001
Created June 26, 2014 18:47
Show Gist options
  • Save sudheesh001/179fe6a0eda9de570768 to your computer and use it in GitHub Desktop.
Save sudheesh001/179fe6a0eda9de570768 to your computer and use it in GitHub Desktop.
Palindrome check of a string.
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
int isPalindrome(char* str)
{
static int length = strlen(str);
if (length<1)
return 1;
if (str[0] == str[length-1])
{
length -= 2;
return isPalindrome (str+1);/*Recursive call as the function isPalindrome
is called again within itself*/
}
else
return 0;
}
int main (void)
{
int result;
char* str;
gets(str);/*Input a string to check whether it is a palindrome or not*/
//cout<<str;
result = isPalindrome(str);/*The function isPalindrome is called.It takes a string
argument and returns a value 0 or 1 which is stored in
the integer variable "result"*/
if (result==1)
cout<<"Palindrome\n";
else
cout<<"Not Palindrome\n";
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment