Program 5
Palindrome
Write logical part for checking palindrome of string in given code.
Input: S = “abba”
Output: 1
Incorrect Code
Correct Code
Incorrect Code
int isPalindrome(string S)
{
int left=0;
int right=S.length()-1;
while(left<=right){
if( ){
return 0;
}else{
left ;
right ;
}
}
if( ){
return 1;
}
}
Correct Code
int isPalindrome(string S)
{
int left=0;
int right=S.length()-1;
while(left<=right){
if(S[left]!=S[right]){
return 0;
}else{
left++;
right--;
}
}
if(left>right){
return 1;
}
}

Login/Signup to comment