Palindrome Program in C++:
C program for palindrome
or palindrome in cprogramming: palindrome program in c language, c code to
check if a string is a palindrome or not and for palindrome number.
Palindrome number in c: A
palindrome number is a number such that if we reverse it, it will not change.
For example some palindrome numbers examples are 121, 212, 12321, -454.
Palindrome number algorithm
1. Get the number from
user.
2. Reverse it.
3. Compare it with the number entered by the user.
4. If both are same then print palindrome number
5. Else print not a palindrome number.
2. Reverse it.
3. Compare it with the number entered by the user.
4. If both are same then print palindrome number
5. Else print not a palindrome number.
//C++ program : To check whether a given number is palindrome or not
#include
using namespace std;
int main()
{
int n, num, digit, reverse = 0;
cout << "Enter a positive number:- ";
cin >> num;
n = num;
do
{
digit = num%10;
reverse = (reverse*10) + digit;
num = num/10;
}while (num!=0);
cout << " The reverse of the number is: " << reverse << endl;
if (n = = reverse)
cout << " The number is a palindrome";
else
cout << " The number is not a palindrome";
return 0;
}
Palindrome Number Program in C++
ReplyDeleteA Palindrome number is a number that remains the same when its digits are reversed. Like 16461, for example: we take 121 and reverse it, after revers it is same as original.