Q:

Write a program in C++ to check whether a given number is palindrome or not

0

Write a program in C++ to check whether a given number is palindrome or not.

Sample Output:

Check whether a given number is palindrome or not:                    
 -------------------------------------------------------               
 Input a number: 141                                                   
 141 is a Palindrome Number.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
using namespace std;
int main()
{
    int i,n1,r,s=0;
 cout << "\n\n Check whether a given number is palindrome or not: \n";
 cout << " -------------------------------------------------------\n";
 	cout << " Input a number: ";
    cin>>n1;	
    for(i=n1;i>0; )
    {
        r=i % 10;
        s=s*10+r;
        i=i/10;
    }
    if(s==n1)
    {
        cout<<" "<<n1<<" is a Palindrome Number."<<endl;
    }
    else
    {
        cout<<" "<<n1<<" is a not Palindrome Number."<<endl;
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now