Count minimum moves required to convert A to B | C ++ program for the above approach ; Function to find minimum number of moves to obtained B from A ; Stores the minimum number of moves ; Absolute difference ; K is in range [ 0 , 10 ] ; Print the required moves ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void convertBfromA ( int a , int b ) { int moves = 0 ; int x = abs ( a - b ) ; for ( int i = 10 ; i > 0 ; i -- ) { moves += x / i ; x = x % i ; } cout << moves << " ▁ " ; } int main ( ) { int A = 188 , B = 4 ; convertBfromA ( A , B ) ; return 0 ; }