3D Array Example – Cuboid Volume Calculation

#include <stdio.h>

#define LENGTH 2
#define WIDTH 3
#define HEIGHT 4

int main() {
    // Cuboid volume calculation using a 3D array
    int cuboid[LENGTH][WIDTH][HEIGHT];

    // Initialize cuboid dimensions
    for (int i = 0; i < LENGTH; i++) {
        for (int j = 0; j < WIDTH; j++) {
            for (int k = 0; k < HEIGHT; k++) {
                cuboid[i][j][k] = i + j + k; // Arbitrary initialization for demonstration
            }
        }
    }

    // Calculate and print the cuboid volumes
    printf("Cuboid Volumes:\n");
    for (int i = 0; i < LENGTH; i++) {
        for (int j = 0; j < WIDTH; j++) {
            for (int k = 0; k < HEIGHT; k++) {
                printf("Volume[%d][%d][%d]: %d\n", i, j, k, cuboid[i][j][k]);
            }
        }
    }

    return 0;
}
chevron_left
chevron_right

Leave a comment

Your email address will not be published. Required fields are marked *

Comment
Name
Email
Website