diff --git a/string_problems/palindrome_check.cpp b/string_problems/palindrome_check.cpp new file mode 100644 index 0000000..6f1c8fd --- /dev/null +++ b/string_problems/palindrome_check.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; + +bool isPalindrome(string s) { + int i = 0, j = s.length() - 1; + while (i < j) { + if (s[i] != s[j]) + return false; + i++; + j--; + } + return true; +} + +int main() { + string s; + cout << "Enter a string: "; + cin >> s; + if (isPalindrome(s)) + cout << s << " is a palindrome." << endl; + else + cout << s << " is not a palindrome." << endl; + return 0; +}