Minimum steps to reach the Nth stair in jumps of perfect power of 2 | C ++ program for the above approach ; Function to count the number of jumps required to reach Nth stairs . ; Till N becomes 0 ; Removes the set bits from the right to left ; Driver Code ; Number of stairs ; Function Call
#include " bits / stdc + + . h " NEW_LINE using namespace std ; int stepRequired ( int N ) { int cnt = 0 ; while ( N ) { N = N & ( N - 1 ) ; cnt ++ ; } return cnt ; } int main ( ) { int N = 23 ; cout << stepRequired ( N ) ; return 0 ; }