I have an algorithm regarding the motion of a particle. It can only hop one step to the right or remain still. I want to construct a square board(N*N dimensional array) that shows the correlation between time and distance.
so it'll look something like
*this table shows that if the particle a hops every time, at time 5 it would be at Distance = 5*Code:D\T 0 1 2 3 4 5 0 a 1 x a 2 x x a 3 x x x a 4 x x x x a 5 x x x x x a
*this table shows that if the particle a hops every time except the firts time, at time 5 it would be at Distance = 4*Code:D\T 0 1 2 3 4 5 0 a a 1 x x a 2 x x x a 3 x x x x a 4 x x x x x a 5 x x x x x x
Assume the particle starts at zero, if it hops one step after 1 second, then a would move to [1][1], because that represents at T = 1, the particle is at D = 1. else, it would move to [1][0], because it did not hop at T = 1, and thus particle is at D = 0.
I have not had much experience with multidimensional arrays. I understand you have to allocate the memory for it first.
I'm having trouble with placing the particle in the corresponding [][]. Using two for-loops, I think I have set the each tile of the square into an empty state:Code:c = (double *) malloc (N * N * sizeof *c); /* to allocated a flexible multidimensional array so N can vary upon command line input */
I'm not sure how I would go about inputing values into the square. How would the for-loop be constructed?Code:for(i = 0; i < t; i++) { for(j = 0; j < t; j++) { c[i*t+j] = 0.0; } }
*edit* Also, how are multi-dimensional arrays printed? right now I have no way to check my code to see if it is what I want it to do becuase idk how to print it :P.