#include <stdio.h>
int do_something (const int size_of_array, const int *array)
{
int index = 0;
for (index = 0; index < size_of_array; index++)
{
printf("array[%d], %d ", index, array[index]);
}
printf("\n");
return 0;
}
int nested_for (int current_index, const int size_of_array, int* array)
{
for (array[current_index] = 0; array[current_index] < 3; array[current_index]++)
{
current_index--;
for (array[current_index] = 0; array[current_index] < 3; array[current_index]++)
{
current_index--;
for (array[current_index] = 0; array[current_index] < 3; array[current_index]++)
{
do_something(size_of_array, array);
}
current_index++;
}
current_index++;
}
return 0;
}
int recursive (const int current_index, const int size_of_array, int* array)
{
if (current_index < 0) {
do_something(size_of_array, array);
} else {
for (array[current_index] = 0; array[current_index] < 3; array[current_index]++)
{
recursive(current_index - 1, size_of_array, array);
}
}
return 0;
}
int main ()
{
int current_index = 3;
int size_of_array = 3;
int array[3] = {};
nested_for(current_index - 1, size_of_array, array);
recursive(current_index - 1, size_of_array, array);
return 0;
}