Guest User

Untitled

a guest
Nov 23rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Online C Compiler.
  4. Code, Compile, Run and Debug C program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <stdio.h>
  10.  
  11. int main()
  12. {
  13. char string[25], reverseString[25] = {'\0'};
  14. int i, length = 0, flag = 0;
  15.  
  16. fflush(stdin);
  17. printf("Enter a word \n");
  18. gets(string);
  19.  
  20. for(int i = 0; string[i] != '\0'; i++){
  21. string[i] = tolower(string[i]);
  22. }
  23. /* keep going through each character of the string till its end */
  24. for (i = 0; string[i] != '\0'; i++)
  25. {
  26. length++;
  27. }
  28. for (i = length - 1; i >= 0; i--)
  29. {
  30. reverseString[length - i - 1] = string[i];
  31. }
  32. /*
  33. * Compare the input string and its reverse. If both are equal
  34. * then the input string is palindrome.
  35. */
  36. for (i = 0; i < length; i++)
  37. {
  38. if (reverseString[i] == string[i])
  39. flag = 1;
  40. else
  41. flag = 0;
  42. }
  43. if (flag == 1)
  44. printf("%s is a palindrome \n", string);
  45. else
  46. printf("%s is not a palindrome \n", string);
  47. return 0;
  48. }
Add Comment
Please, Sign In to add comment