top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to check given Number is same after 180 degree rotation?

+2 votes
309 views

Check given Number is same after 180 degree rotation?

Input: 69
Output: True

Input: 916
Output: True

Input: 89
Output: False

posted Feb 25, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Isn't the idea same as palindrome but instead of checking the same characters you will have to check the below map
[6, 9]
[9, 6]
If the number encountered is 6 then at the other end it should have 9 and vice versa.

#include <stdio.h>
#include <math.h>

long rotate180(long x){
    long q, r, y=0,c=0;
    q=x;
    while(q>;0){
        r=q%10;
        q=q/10;
        if(r!=8 && r!=0 && r!=1 && r!=6 && r!=9)
        return 0;
        if(r==6)r=9;
        else if(r==9)r=6;
        y=r+y*(10);
    }
    printf("y is set to: '%lld'\n",y);
    return y;
}


int main()
{
    long n=99166;
    long r=rotate180(n);
    if(r!=0 && r==n)
    printf("They are equal after 180 degree rotation\n");
    else
    printf("Failed");
    return 0;
}
answer Feb 26, 2016 by Manikandan J
...