Skip to content

Commit 1c2df83

Browse files
authored
Merge pull request #477 from TermKnive/master
An algorithm that checks for a string palindrome.
2 parents b3030be + ab6cc16 commit 1c2df83

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

StringPalindrome.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
char str1[20];
5+
int i, length;
6+
int flag = 0;
7+
8+
int main() {
9+
10+
cout << "Enter a string: ";
11+
cin >> str1;
12+
13+
length = strlen(str1);
14+
15+
for (i = 0; i < length; i++) {
16+
if (str1[i] != str1[length - i - 1]) {
17+
flag = 1;
18+
break;
19+
}
20+
}
21+
22+
if (flag) {
23+
cout << str1 << " is not a palindrome" << endl;
24+
}
25+
else {
26+
cout << str1 << " is a palindrome" << endl;
27+
}
28+
return 0;
29+
}

0 commit comments

Comments
 (0)