forked from riyaaa04/cpp20
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14.cpp
More file actions
37 lines (29 loc) · 606 Bytes
/
14.cpp
File metadata and controls
37 lines (29 loc) · 606 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//Implement a program that checks if a string is a palindrome.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str, temp;
int i = 0, j;
cout << "Enter a string to check for Palindrome: ";
cin >> str;
temp = str;
j = str.length() - 1;
//Reversing the temp string.
while (i < j)
{
swap(str[i], str[j]);
i++;
j--;
}
if (temp == str)
{
cout << "The string is a palindrome." << endl;
}
else
{
cout << "The string is not a palindrome." << endl;
}
return 0;
}