Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. // Lab3.4.Palindrome.cpp : Defines the entry point for the console application.
  2. // A program that checks if a word is a palindrome
  3. // Written by Louise Mao ID 10948994
  4.  
  5. #include <iostream>
  6. #include <string>
  7. using namespace std;
  8.  
  9. bool palindrome(string word) {
  10.     bool flag;
  11.     int length = word.length();
  12.     for (int i = 0; i < (length / 2); i++) {
  13.         cout << word[i] << " ?= " << word[length - i] << endl;
  14.         if (word[i] == word[length - i]) {
  15.             flag = true;
  16.         }
  17.         else {
  18.             flag = false;
  19.             //break;
  20.         }
  21.     }
  22.     return flag;
  23. }
  24.  
  25. int main()
  26. {
  27.     string word;
  28.     bool n;
  29.  
  30.     cout << "Enter a word" << endl;
  31.     cin >> word;
  32.     n = palindrome(word);
  33.  
  34.     cout << n << endl;
  35.     return 0;
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement