Check if an integer is rotation of another given integer | C # implementation of the approach ; Function to check if the integer A is a rotation of the integer B ; Stores the count of digits in A ; Stores the count of digits in B ; If dig1 not equal to dig2 ; Stores position of first digit ; Stores the first digit ; Rotate the digits of the integer ; If A is equal to B ; If A is equal to the initial value of integer A ; Driver Code
using System ; public class GFG { static int check ( int A , int B ) { if ( A == B ) { return 1 ; } int dig1 = ( int ) Math . Floor ( Math . Log10 ( A ) + 1 ) ; int dig2 = ( int ) Math . Floor ( Math . Log10 ( B ) + 1 ) ; if ( dig1 != dig2 ) { return 0 ; } int temp = A ; while ( true ) { int power = ( int ) Math . Pow ( 10 , dig1 - 1 ) ; int firstdigit = A / power ; A = A - firstdigit * power ; A = A * 10 + firstdigit ; if ( A == B ) { return 1 ; } if ( A == temp ) { return 0 ; } } } public static void Main ( String [ ] args ) { int A = 967 , B = 679 ; if ( check ( A , B ) == 1 ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }