text: Convert a number m to n using minimum number of given operations | C # implementation to convert a number m to n using minimum number of given operations ; function to find minimum number of given operations to convert m to n ; only way is to do - 1 ( m - n ) times ; not possible ; n is greater and n is odd ; perform ' - 1' on m ( or + 1 on n ) ; n is even ; perform ' * 2' on m ( or n / 2 on n ) ; Driver code
code: using System ; class GFG { static int convert ( int m , int n ) { if ( m == n ) return 0 ; if ( m > n ) return m - n ; if ( m <= 0 && n > 0 ) return - 1 ; if ( n % 2 == 1 ) return 1 + convert ( m , n + 1 ) ; else return 1 + convert ( m , n / 2 ) ; } public static void Main ( ) { int m = 3 , n = 11 ; Console . Write ( " Minimum ▁ number ▁ of ▁ " + " operations ▁ : ▁ " + convert ( m , n ) ) ; } }