From 0c8515657303d2cdafc33dafed35dd0cda9f9d7d Mon Sep 17 00:00:00 2001 From: Krishna Vedala Date: Thu, 28 May 2020 11:24:36 -0400 Subject: [PATCH] document number palindrome --- others/palindrome_of_number.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/others/palindrome_of_number.cpp b/others/palindrome_of_number.cpp index 621b09ab6..66401ff96 100644 --- a/others/palindrome_of_number.cpp +++ b/others/palindrome_of_number.cpp @@ -1,3 +1,10 @@ +/** + * @file + * @brief Check if a number is + * [palindrome](https://en.wikipedia.org/wiki/Palindrome) or not. + * + * This program cheats by using the STL library's std::reverse function. + */ #include #include @@ -8,17 +15,18 @@ #include #endif +/** Main function */ int main() { int num; std::cout << "Enter number = "; std::cin >> num; - std::string s1 = std::to_string(num); + std::string s1 = std::to_string(num); // convert number to string std::string s2 = s1; - reverse(s1.begin(), s1.end()); + std::reverse(s1.begin(), s1.end()); // reverse the string - if (s1 == s2) + if (s1 == s2) // check if reverse and original string are identical std::cout << "true"; else std::cout << "false";