Jan 24, 2022

Hacker-Rank Problem-Boxes through tunnel-in C language

Boxes Through Tunnel-Hacker-rank-(C lang)

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

int is_lower_than_max_height(box b)
{
    if (b.height<MAX_HEIGHT)
    {
        return 1;
    }
    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

Comparing two files in C language.

Operations on More than one File.    # include < stdio.h > # include < stdlib.h > # include < string.h > int main ( int ...