Advertisement
Felanpro

Palindrome tester

Feb 22nd, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     //A program that checks if a string is a palindrome
  8.  
  9.     while(1)
  10.     {
  11.     string x;
  12.     cout << "Input the word: ";
  13.     cin >> x;
  14.  
  15.     int length_of_string = 0;
  16.  
  17.     while(x[length_of_string] != '\0')
  18.         length_of_string++;
  19.  
  20.     int breaking = 0;
  21.  
  22.     for(int t = 0, p = length_of_string - 1; t < length_of_string; t++, p--)
  23.     {
  24.         if(x[t] != x[p])
  25.         {
  26.             breaking = 1;
  27.         }
  28.         if(breaking == 1)
  29.             break;
  30.     }
  31.  
  32.     if(breaking == 0)
  33.     {
  34.         cout << "The word is a palindrome!" << endl;
  35.     }
  36.     else
  37.         cout << "The word is not a palindrome!" << endl;
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement