You are viewing a single comment's thread. Return to all comments →
struct box { /** * Define three fields of type int: length, width and height */ int length,width,height; };
typedef struct box box;
int get_volume(box b) { /** * Return the volume of the box */ return b.length*b.height*b.width; }
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
int main() { int n; scanf("%d", &n); box *boxes = malloc(n * sizeof(box)); 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 (is_lower_than_max_height(boxes[i])) { printf("%d\n", get_volume(boxes[i])); } } return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Boxes through a Tunnel
You are viewing a single comment's thread. Return to all comments →
include
include
define MAX_HEIGHT 41
struct box { /** * Define three fields of type int: length, width and height */ int length,width,height; };
typedef struct box box;
int get_volume(box b) { /** * Return the volume of the box */ return b.length*b.height*b.width; }
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
int main() { int n; scanf("%d", &n); box *boxes = malloc(n * sizeof(box)); 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 (is_lower_than_max_height(boxes[i])) { printf("%d\n", get_volume(boxes[i])); } } return 0; }