Palindrome Number Program in C++
Hello friends, Hitesh is here; Today we will write Palindrome Number Program in C++. It is very simple and easy. Palindrome number is number which is same after reverse it. So in case of programming we need to first reverse given number and then compare with original number if number is same it means given number is palindrome number.For example 121 is palindrome number.
Code for Program
#include <stdio.h>
#include <iostream.h>
int main()
{
int n, reverse = 0, temp;
cout<<"Enter any number:";
cin>>n;
temp = n;
while( temp != 0 )
{
reverse = reverse * 10;
reverse = reverse + temp%10;
temp = temp/10;
}
if ( n == reverse )
cout<<"Palindrome number";
else
cout<<"Not a palindrome number.";
return 0;
}
Output:
Enter any number: 121
Palindrome number
No comments:
Post a Comment