Complete the code to check if a string is a palindrome by comparing characters from start and end.
int isPalindrome(char str[]) {
int start = 0;
int end = strlen(str) - 1;
while (start < end) {
if (str[start] != str[[1]]) {
return 0;
}
start++;
end--;
}
return 1;
}We compare the character at the start index with the character at the end index to check for palindrome.
Complete the code to calculate the length of the string for palindrome check.
int length = [1](str);The strlen function returns the length of a string in C.
Fix the error in the palindrome check loop condition.
while (start [1] end) { if (str[start] != str[end]) { return 0; } start++; end--; }
The loop should continue while start is less than end to compare characters from both ends.
Fill both blanks to correctly reverse the string for palindrome comparison.
int len = strlen(str); char rev[len + 1]; for (int i = 0; i < len; i++) { rev[[1]] = str[[2]]; } rev[len] = '\0';
To reverse the string, assign rev[len - 1 - i] the character from str[i].
Fill all three blanks to create a function that returns 1 if palindrome, else 0.
int isPalindrome(char str[]) {
int start = 0;
int end = [1](str) - 1;
while (start [2] end) {
if (str[start] != str[end]) {
return [3];
}
start++;
end--;
}
return 1;
}The function uses strlen to get length, loops while start < end, and returns 0 if mismatch found.
