1string input;
2
3cout << "Please enter a string: ";
4cin >> input;
5
6if (input == string(input.rbegin(), input.rend())) {
7 cout << input << " is a palindrome";
8}
9
1#include <iostream>
2using namespace std;
3
4bool isPalindrome(int x) {
5 int rem,reverse=0;
6 while(x!=0){
7 rem=x%10;
8 reverse=reverse*10+rem;
9 x/=10;
10 if (x == reverse) return true;
11 else return false;
12 }
13 return true;
14}
15
16int main() {
17 int n;
18 cin >>n;
19
20 if(isPalindrome(n)) {
21 cout <<n<<" is a palindrome";
22 }
23 else {
24 cout << n<<" is NOT a palindrome";
25 }
26 return 0;
27}
1#include<iostream>
2#include<string>
3#include<algorithm>
4bool IsPalindrome_true_false(const std::string& );
5int main ()
6{
7
8 std::cout<<"Please enter a string:\t";
9 std::string str;
10 getline(std::cin, str);
11
12 // convert the string from uppercase to lowercase
13 int i = 0;
14 while(str[i])
15 {
16 if(str[i] == std::toupper(str[i]) && std::isalpha(str[i]) == 1024)
17 str[i]+= 32;
18 ++i;
19 }
20 // looping while string is empty
21 while(str.empty())
22 {
23 std::cout<<"\nPlease enter a string your string is empty:\t";
24 if(!str.empty())
25 std::string str;
26 getline(std::cin, str);
27 }
28
29 std::cout<<"\n"<<std::boolalpha<<IsPalindrome_true_false(str)<<std::endl;
30 std::cout<<std::endl;
31
32 return 0;
33}
34
35// check if string is a palindrome and return true or false
36bool IsPalindrome_true_false(const std::string& str)
37{
38
39 int i = 0;
40 int j = str.length() - 1;
41
42 while(i <= j )
43 {
44
45 if(std::isalpha(str[i]) == 0){
46 ++i;
47 continue;
48 }else if(std::isalpha(str[j]) == 0){
49 --j;
50 continue;
51 }
52 if(str[i] != str[j]){
53
54 return false;
55 }
56 ++i;
57 --j;
58 }
59 return true;
60}
61
62
63
64