From 227dcf0525e2a60f1c2209a9de8e492f868c186b Mon Sep 17 00:00:00 2001 From: Gopikrishnan Rajeev Date: Wed, 31 Oct 2018 00:05:32 +0530 Subject: [PATCH 1/2] Added and algorithm to check if a number is palindrome Added the algorithm to convert number to string and check if it's a palindrome. --- Palindromeofnumber.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Palindromeofnumber.cpp diff --git a/Palindromeofnumber.cpp b/Palindromeofnumber.cpp new file mode 100644 index 000000000..a960ec854 --- /dev/null +++ b/Palindromeofnumber.cpp @@ -0,0 +1,20 @@ +#include +using namespace std; + +int main() +{ +int num; +cin>>num; + +string s1 = to_string(num); +string s2 = s1; + +reverse(s1.begin(),s1.end()); + +if(s1==s2) + cout<<"true"; +else + cout<<"false"; + +return 0; +} From 9e6cd3bb7ceba514ecd510fbf633ee13dcfd3a4b Mon Sep 17 00:00:00 2001 From: Ashwek Swamy <39827514+ashwek@users.noreply.github.com> Date: Sun, 10 Feb 2019 12:10:29 +0530 Subject: [PATCH 2/2] Update Palindromeofnumber.cpp --- Palindromeofnumber.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Palindromeofnumber.cpp b/Palindromeofnumber.cpp index a960ec854..8bfdfb073 100644 --- a/Palindromeofnumber.cpp +++ b/Palindromeofnumber.cpp @@ -1,20 +1,23 @@ -#include +#include +#include + using namespace std; int main() { -int num; -cin>>num; + int num; + cout << "Enter number = "; + cin >> num; -string s1 = to_string(num); -string s2 = s1; + string s1 = to_string(num); + string s2 = s1; -reverse(s1.begin(),s1.end()); + reverse(s1.begin(),s1.end()); -if(s1==s2) - cout<<"true"; -else - cout<<"false"; + if(s1 == s2) + cout<<"true"; + else + cout<<"false"; -return 0; + return 0; }