Answer:
The solution code is written in C.
- #include <stdio.h>
- #include <string.h>
- #include <stdbool.h>
- bool isPalindrome(char str[])
- {
- int length = strlen(str) ;
- bool status = true;
- int i;
-
- for(i = 0; i < length / 2; i++){
-
- if(str[i] != str[length - 1 - i]){
- status = false;
- return status;
- }
- }
-
- return status;
- }
Explanation:
Firstly, we need to include libraries<em> stdio, string </em>and<em> stdbool </em> (Line 1 -3)<em>.</em>
Next, we create a function<em> isPalindrome</em> that take one string parameter and return a boolean value (Line 5).
We use function strlen to get the length to the input string (Line 7). At this point, let's set our <em>status</em> as true (Line 8).
We create a for-loop to traverse through the characters inside the input string (Line 11). Within the loop, we set a condition that compare the first letter to the letter started from the last index (Line 13). If the letters are not matched, this means the input string is not a palindrome and set the status as false and return it as output (Line 14 - 15).
Otherwise, the for-loop will just terminate without running the statements within the if-block and return status as true (Line 19).