Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- //A program that checks if a string is a palindrome
- while(1)
- {
- string x;
- cout << "Input the word: ";
- cin >> x;
- int length_of_string = 0;
- while(x[length_of_string] != '\0')
- length_of_string++;
- int breaking = 0;
- for(int t = 0, p = length_of_string - 1; t < length_of_string; t++, p--)
- {
- if(x[t] != x[p])
- {
- breaking = 1;
- }
- if(breaking == 1)
- break;
- }
- if(breaking == 0)
- {
- cout << "The word is a palindrome!" << endl;
- }
- else
- cout << "The word is not a palindrome!" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement