Convert A into B by incrementing or decrementing 1 , 2 , or 5 any number of times | C ++ program for the above approach ; Function to find minimum number of moves required to convert A into B ; Stores the minimum number of moves required ; Stores the absolute difference ; FInd the number of moves ; Return cnt ; Driver Code ; Input ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int minimumSteps ( int a , int b ) { int cnt = 0 ; a = abs ( a - b ) ; cnt = ( a / 5 ) + ( a % 5 ) / 2 + ( a % 5 ) % 2 ; return cnt ; } int main ( ) { int A = 3 , B = 9 ; cout << minimumSteps ( A , B ) ; return 0 ; }