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

+2 votes
75 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
Share this question

## 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
Similar Questions
+2 votes

How to find prime numbers between given intervals? Sample code along with the complexity would be helpful?

0 votes