Boxes through a Tunnel in C - Online Judge

Latest

This is an Online Judge Solution Base Site. We can discuss & Solve any contest solution in Programming.

Monday, March 23, 2020

Boxes through a Tunnel in C

Solution in C:-

#include <stdio.h>
#include <stdlib.h>
#define MAX_HEIGHT 41
struct box 
{
    int length,width, height;
};
typedef struct box box;
int get_volume(box b) {

    return b.length*b.width*b.height;
}
int is_lower_than_max_height(box b) {
    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 = 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;
}

No comments:

Post a Comment

Thanks..