Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 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 "stdafx.h"
  6. #include <iostream>
  7. #include <string>
  8. using namespace std;
  9.  
  10. bool palindrome(string word) {
  11. bool flag;
  12. int length = word.length()
  13. for (int i = 0; i < (length / 2); i++) {
  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