Advertisement
kubbur

Untitled

Feb 2nd, 2017
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. // isPalindrome.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <string>
  7. using namespace std;
  8.  
  9.  
  10. string isPalindrome(string inntak);
  11. int main()
  12. {
  13. system("chcp 1252>NUL");
  14.  
  15. string test = "";
  16. string lausn = "";
  17. cout << "sláðu inn orð sem þú vilt prófa: ";
  18. cin >> test;
  19. lausn = isPalindrome(test);
  20. cout << lausn;
  21. return 0;
  22. }
  23.  
  24. string isPalindrome(string inntak)
  25. {
  26. string nidurstada = "";
  27. int lengd = inntak.length;
  28. string ofugt = "";
  29. for (int i = lengd; i >= 0; i--);
  30. ofugt += inntak[i];
  31. if (inntak == ofugt)
  32. {
  33. nidurstada = "þettað orð er palindrome";
  34. }
  35. else
  36. {
  37. nidurstada = "þettað orð er ekki palindrome";
  38. }
  39. return nidurstada;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement