Sunday, April 5, 2020

Boxes through a Tunnel - Hacker Rank Solution

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;
}

1 comment:

Powered by Blogger.