check if the c code is a palindrome
#include <stdio.h>
#include <string.h>
int isPalindrome(char str[]) {
int i, j;
int len = strlen(str);
for (i = 0, j = len - 1; i < j; i++, j--) {
if (str[i] != str[j]) {
return 0;
}
}
return 1;
}
int main() {
char str[100];
printf("Enter a string: ");
scanf("%s", str);
if (isPalindrome(str)) {
printf("The string is a palindrome.\n");
} else {
printf("The string is not a palindrome.\n");
}
return 0;
}
This C code checks if a given string is a palindrome. It uses a function isPalindrome()
to iterate over the string and compare characters from the beginning and end. If any pair of characters doesn't match, the function returns 0 indicating that the string is not a palindrome. If all the pairs of characters match, the function returns 1 indicating that the string is a palindrome. In the main()
function, the user is prompted to enter a string and the result is printed based on the return value of the isPalindrome()
function.