Check Palindrome (recursive)
Send Feedback
Check whether a given String S is a palindrome using recursion. Return true or false.
Input Format :
Output Format :
Constraints :
Sample Input 1 :
Sample Output 1:
Sample Input 2 :
Sample Output 2:
String S
'true' or 'false'
0 <= |S| <= 1000
where |S| represents length of string S.
racecar
true
ninja
false
SOLUTION:-
#include <iostream>
using namespace std;
#include<string.h>
bool checkPalindrome(char input[]) {
// Write your code here
static int i=0;
int S=strlen(input);
if(i>=S)
return 1;
if(input[i]!=input[S-i-1])
{
return 0;
}
else
{
i++;
checkPalindrome(input);
}
}
int main() { char input[50]; cin >> input; if(checkPalindrome(input)) { cout << "true" << endl; } else { cout << "false" << endl; } }
This is dummy text. It is not meant to be read. Accordingly, it is difficult to figure out when to end it. But then, this is dummy text. It is not meant to be read. Period.
If you have any doubts then please let me know... ConversionConversion EmoticonEmoticon