Skip to content

Instantly share code, notes, and snippets.

@wurikiji

wurikiji/test.c Secret

Created August 12, 2021 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wurikiji/bfd87406b4406952f563138dcf0be222 to your computer and use it in GitHub Desktop.
Save wurikiji/bfd87406b4406952f563138dcf0be222 to your computer and use it in GitHub Desktop.
3d array in C, C++
#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