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

#include <iostream>
using namespace std;
void main()
{
    int num,r,sum=0,t;

    cout<<"Input a number: ";
    cin>>num;

    for(t=num;num!=0;num=num/10){
         r=num % 10;
         sum=sum*10+r;
    }
    if(t==sum)
         cout<<t<<" is a palindrome number.\n";
    else
         cout<<t<<" is not a palindrome number.\n";


      system ("pause");
}

Test Data : 
Input a number: 121 
Expected Output :
121 is a palindrome number.
Write a program in C++ to check whether a number is a palindrome or not Write a program in C++ to check whether a number is a palindrome or not Reviewed by Unknown on May 30, 2017 Rating: 5

No comments:

Powered by Blogger.