Hello dear users,
I am currently working on a program simulating physics on a
d-dimensional grid. For this, I need
d nested for loops, which I do not know how to implement!
I hope you can help me, here comes a minimum example of my problem:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#define d X // X can be 1,2,3,... ; chosen before compiling
int main () {
// ...
int count[d] , N = Y ; // Y can be 1,2,3,... ; chosen run-time
for ( count[0] = 0 ; count[0] < N ; count[0]++ )
for ( count[1] = 0 ; count[1] < N ; count[1]++ )
for ( count[2] = 0 ; count[2] < N ; count[2]++ )
// ...
for ( count[d-1] = 0 ; count[d-1] < N ; count[d-1]++ ) {
// CODE
}
// ...
return 0;
}
|
The Code itself is already generalized and compatible with multiple dimensions (depending on the whole
count array) and obviously is to be executed N
d times.
Since the source code significantly depends on the value of
d, I presume that the preprocessor is needed, but that's pretty much where my knowledge on preprocessors ends.
I hope that some of you can assist me, your help is very appreciated!
Thanks in advance,
strangeopi
PS: I do know about the "rolled up index" technique, but if possible, I would like to avoid that method.