Sunday 27 August 2017

Given an integer, check whether it is a palindrome or not.

Input:
The first line of input contains an integer T denoting
the number of test cases. Then T test cases follow. 
Each test case consists of a single line. The first line
of each test case contains a single integer N to be 
checked for palindrome.

Output:
Print "Yes" or "No" (without quotes) depending on

whether the number is palindrome or not.

Constraints:
1 <= T <= 1000
1 <= N <= 100
00

Example:

Input:
3
6
167

55555

Output:
Yes
No

Yes


#include <stdio.h>
int main()
{
    int t;
    int flag;
    scanf("%d",&t);
    while(t--)
    {
        int n,remainder,originalInteger,reversedInteger=0;
        scanf("%d",&n);
        originalInteger = n;
        while( n!=0 )
        {
            remainder = n%10;
            reversedInteger = reversedInteger*10 + remainder;
            n /= 10;
        }
        if(originalInteger==reversedInteger)
            flag=1;
        else
            flag=0;
    if(flag==1)
        printf("Yes\n");
    else if(flag==0)
        printf("No\n");
    }
    return 0;
}

No comments:

Post a Comment