Count number of digits after decimal on dividing a number | C # program to count digits after dot when a number is divided by another . ; int ans = 0 ; Initialize result ; calculating remainder ; if this remainder appeared before then the numbers are irrational and would not converge to a solution the digits after decimal will be infinite ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int count ( int x , int y ) { Dictionary < int , int > m = new Dictionary < int , int > ( ) ; while ( x % y != 0 ) { x = x % y ; ans ++ ; if ( m . ContainsKey ( x ) ) return - 1 ; m . Add ( x , 1 ) ; x = x * 10 ; } return ans ; } public static void Main ( String [ ] args ) { int res = count ( 1 , 2 ) ; if ( ( res == - 1 ) ) Console . WriteLine ( " INF " ) ; else Console . WriteLine ( res ) ; res = count ( 5 , 3 ) ; if ( ( res == - 1 ) ) Console . WriteLine ( " INF " ) ; else Console . WriteLine ( res ) ; res = count ( 3 , 5 ) ; if ( ( res == - 1 ) ) Console . WriteLine ( " INF " ) ; else Console . WriteLine ( res ) ; } }