diff --git a/C++/README.md b/C++/README.md index 6c2a8fec..4ffbcb51 100644 --- a/C++/README.md +++ b/C++/README.md @@ -15,3 +15,4 @@ | Program-10 | Program to find the missing number in a Sorted Array. | Program-15 | Program to find modular exponentiation. +| Program-19| To check whether a number is in palindrome or not \ No newline at end of file diff --git a/C++/program-19/Read me.md b/C++/program-19/Read me.md new file mode 100644 index 00000000..a952e91a --- /dev/null +++ b/C++/program-19/Read me.md @@ -0,0 +1 @@ +# To check whether a number is in palindrome or not \ No newline at end of file diff --git a/C++/program-19/palindrome.cpp b/C++/program-19/palindrome.cpp new file mode 100644 index 00000000..a18f2dd0 --- /dev/null +++ b/C++/program-19/palindrome.cpp @@ -0,0 +1,23 @@ +#include +using namespace std; +int main() +{ + int num, temp, digit, rev = 0; + + cout << "Enter a positive number: "; + cin >> num; + temp = num; + while (num != 0){ + digit = num % 10; + rev = (rev * 10) + digit; + num = num / 10; + } + cout << "The reverse of the number is: " << rev << endl; + if (temp == rev){ + cout<<"The number is a palindrome."; + } + else{ + cout << "The number is not a palindrome."; + } + return 0; +}