Filling 3d array using for loop in C programming -
i'm working on class project , i'm stuck @ basic one. have fill stack of boxes using loops , 3d array. stack 4 width, 4 length , 3 height , have fill boxes 100 items each.
void main(){ int boxshleve[3][4][4]; int i, j, k; (i=0; i<3; ++i){ (j=0; j<4; ++j){ (k=0; k<4; ++k){ boxshleve[3][4][4] = 100; } } } printf("%d", boxshleve[3][4][4]); }
this broken piece of work... how make each array has 100 element in it?
this meant do:
int main() { int boxshleve[3][4][4]; int i, j, k; (i = 0; < 3; ++i) (j = 0; j < 4; ++j) (k = 0; k < 4; ++k) boxshleve[i][j][k] = 100; (i = 0; < 3; i++) (j = 0; j < 4; j++) (k = 0; k < 4; k++) printf("%d ", boxshleve[i][j][k]); return 0; }
the reason need nested loops use i
, j
, k
indexes access array. have use them.
same printing values.
Comments
Post a Comment