-
-
Save wurikiji/bfd87406b4406952f563138dcf0be222 to your computer and use it in GitHub Desktop.
3d array in C, C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void floatt(int row, int col, int height, int *arr) { | |
for(int i = 0 ;i < row; ++i) { | |
for(int j = 0;j < col; ++j) { | |
for(int k = 0 ;k < height; ++k) { | |
printf("%d ", arr[i* col * height + j* height + k]); | |
} | |
printf(" > "); | |
} | |
printf("\n"); | |
} | |
} | |
void floatt2(int arr[][10][10]) { | |
for(int i = 0 ;i < row; ++i) { | |
for(int j = 0;j < col; ++j) { | |
for(int k = 0 ;k < height; ++k) { | |
printf("%d ", arr[i][j][k]); | |
} | |
printf(" > "); | |
} | |
printf("\n"); | |
} | |
} | |
int main(void){ | |
int arr[10][10][10]; | |
for(int i = 0 ;i < 10; ++i) { | |
for(int j = 0;j < 10; ++j) { | |
for(int k = 0 ;k < 10; ++k) { | |
arr[i][j][k] = i * 100 + j * 10 + k; | |
} | |
} | |
} | |
floatt(10, 10, 10, arr); | |
floatt2(arr); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment