Advertisement
k0ske

kiko 2ra string new

Dec 24th, 2021
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. void isPalindrome(char str[])
  6. {
  7. int i, length;
  8. int flag = 0;
  9. length = strlen(str);
  10.  
  11. if (length > 100)
  12. {
  13. cout << "String has characters exceeding the limit!";
  14. }
  15.  
  16. else {
  17. for (i = 0; i < length; i++) {
  18. if (str[i] != str[length - i - 1]) {
  19. flag = 1;
  20. break;
  21. }
  22. }
  23.  
  24. if (flag) {
  25. cout << "The string '" << str << "' is NOT a palindrome!" << endl;
  26. }
  27. else {
  28. cout << "The string '" << str << "' IS a palindrome!" << endl;
  29. }
  30. }
  31. }
  32.  
  33. int main() {
  34. char str[100];
  35. cout << "Enter a string: ";
  36. cin >> str;
  37. isPalindrome(str);
  38. system("pause");
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement