Advertisement
rootuss

palindromy witek

Feb 27th, 2017
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     string wyraz;
  8.     cout << "Podaj wyraz: ";
  9.     cin >> wyraz;
  10.  
  11.     int dlugosc=wyraz.size();
  12.  
  13.  
  14.     for (int i=dlugosc-1; i>=0; i--)
  15.     {
  16.         cout<<wyraz[i];
  17.     }
  18.  
  19.     int i=0;
  20.  
  21.     while (wyraz[i]==wyraz[dlugosc-1-i])
  22.     {
  23.         i++;
  24.     }
  25.     if (i>dlugosc-1-i) cout << endl << "Palindrom";
  26.     else cout << endl << "Nie palindrom";
  27.  
  28.  
  29.  
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement