C Program to check whether a box of entered dimensions can pass through a tunnel or not - HackerRank

 


// Program by Akash Tripathi (@proakash256) 
#include <stdio.h>
#include <stdlib.h>
#define MAX_HEIGHT 41
struct box
{
    /**
    * Define three fields of type int: length, width and height
    */
    int length;
    int width;
    int height;
};
typedef struct box box;
int get_volume(box b) {
    /**
    * Return the volume of the box
    */
    int v = (b.length) * (b.width) * (b.height);
    return v;
}

int is_lower_than_max_height(box b) {
    /**
    * Return 1 if the box's height is lower than MAX_HEIGHT and 0 otherwise
    */
    if((b.height) < MAX_HEIGHT)
        return 1;
    else
        return 0;
}

int main()
{
    int n;
    scanf("%d", &n);
    box *boxes = malloc(n * sizeof(box));
    for (int i = 0i < ni++) {
        scanf("%d%d%d", &boxes[i].length, &boxes[i].width, &boxes[i].height);
    }
    for (int i = 0i < ni++)
    {
        if (is_lower_than_max_height(boxes[i]) == 1)
        {
            printf("%d\n"get_volume(boxes[i]));
        }
    }
    return 0;
}

Comments