Per il discorso dei for annidati, basta fare una funzione ricorsiva.
Amaro C++, il gusto pieno dell'undefined behavior.
Regole del Forum