21 Matchsticks Problem | C ++ implementation of the approach ; Function to return the optimal strategy ; Removing matchsticks in blocks of five ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void TwentyoneMatchstick ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i += 1 ) { cout << 5 - arr [ i ] << " ▁ " ; } cout << endl ; } int main ( ) { int arr [ ] = { 3 , 4 , 2 , 2 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; TwentyoneMatchstick ( arr , N ) ; return 0 ; }