Palindrome number
A palindrome number is one that remains the same on reversal. Some examples are 8, 121, 212, 12321, -454. To check if a number is a palindrome or not, we reverse it and compare it with the original number, if both are the same, it's a palindrome otherwise not. Its...
The first question was...
If you solve the problem, it's very good.
Do you have still doubt then let's check solution-
#include <iostream>
#include<math.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int k=n;
int last_digit;
int count=0;
while(k){
k=k/10;
count++;
}
k=n;
int rev=0;
int i=1;
while(k){
last_digit=k%10;
k=k/10;
rev=rev+last_digit*pow(10,count-i);
i++;
}
if(n==rev){
cout<<"Y"<<endl;
}
else{
cout<<"N"<<endl;
}
}
}
Thanks.

Nice
ReplyDeleteNice
ReplyDelete