From 64aa3042d1e4c7087e22feaf7f93562c91efc3e6 Mon Sep 17 00:00:00 2001 From: harshp807 <57705751+harshp807@users.noreply.github.com> Date: Thu, 7 Oct 2021 08:06:50 +0530 Subject: [PATCH] Create palindrome_or_not_using_class_and_object.cpp --- palindrome_or_not_using_class_and_object.cpp | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 palindrome_or_not_using_class_and_object.cpp diff --git a/palindrome_or_not_using_class_and_object.cpp b/palindrome_or_not_using_class_and_object.cpp new file mode 100644 index 0000000..7370788 --- /dev/null +++ b/palindrome_or_not_using_class_and_object.cpp @@ -0,0 +1,36 @@ +#include +using namespace std; + +class Test { +public: + + int reverse(int x) { + int r, rev = 0; + + while (x > 0) { + r = x % 10; + rev = rev * 10 + r; + x = x / 10; + } + return rev; + } +}; + +int main() { + + int x, rev; + + cout << "Enter a number:"; + cin >> x; + + Test obj; + rev = obj.reverse(x); + + if (rev == x) { + cout << "Number is palindrome:" << x; + } else { + cout << "Number is not palindrome:" << x; + } + + return 0; +}