Boxes through a Tunnel - Hacker Rank Solution
In order to get volume of the box, one should multiply its length, width and height:
return box.length * box.width * box.height;
and to compare the height with we just write
return box.height < MAX_HEIGHT
#include <stdio.h> struct Box { int length, width, height; }; int volume(struct Box box) { return box.length*box.width*box.height; } int lower(struct Box box, int maxHeight) { return box.height < maxHeight; } int main() { int n; scanf("%d", &n); struct Box boxes[100]; for (int i = 0; i < n; i++) scanf("%d%d%d", &boxes[i].length, &boxes[i].width, &boxes[i].height); for (int i = 0; i < n; i++) if (lower(boxes[i], 41)) printf("%d\n", volume(boxes[i])); return 0; }
Boxes through a Tunnel C – Hacker Rank Solution
ReplyDeletehttps://www.codeworld19.com/boxes-through-a-tunnel-c-hacker-rank-solution/