From 0c9669f2a89cfeefdf0601b2c73da267c104a897 Mon Sep 17 00:00:00 2001 From: SMRITI PRAJAPATI <143401846+Smriti-Prajapati@users.noreply.github.com> Date: Sat, 20 Sep 2025 13:49:31 +0530 Subject: [PATCH] Add palingrome check problem in string_problems --- string_problems/palindrome_check.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 string_problems/palindrome_check.cpp 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; +}