fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdbool.h>
  4.  
  5. bool is_palindrome(char string[]);
  6.  
  7. int main(void) {
  8. char string1[] = "is a palindrome!";
  9. char string2[] = "abccba";
  10. char string3[] = "abcdcba";
  11.  
  12. if (is_palindrome(string1))
  13. printf("%s\n- is a palindrome",
  14. string1);
  15. else
  16. printf("%s\n- is not a palindrome",
  17. string1);
  18.  
  19. return 0;
  20. }
  21.  
  22. bool is_palindrome(char string[]){
  23. int middle = strlen(string) /2;
  24. int len = strlen(string);
  25.  
  26. for (int i = 0; i < middle; i++){
  27. if (string[i] != string[len -i -1])
  28. return false;
  29.  
  30. return true;
  31. }
  32. }
  33.  
  34.  
  35.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
is a palindrome!
- is not a palindrome