Boxes through a Tunnel

Sort by

recency

|

162 Discussions

|

  • + 0 comments
    #include <stdio.h>
    #include <stdlib.h>
    #define MAX_HEIGHT 41
    
    struct box
    {
    	int length;
        int width;
        int height;
    };
    
    typedef struct box box;
    
    int get_volume(box b) {
    	/**
    	* Return the volume of the box
    	*/
        return b.length * b.width * b.height;
    }
    
    int is_lower_than_max_height(box b) {
    	/**
    	* Return 1 if the box's height is lower than MAX_HEIGHT and 0 otherwise
    	*/
        return b.height < MAX_HEIGHT;
    }
    
  • + 0 comments
    #include<stdio.h>
    
    int main()
    {
        int n;
        //printf("Enter the number of boxes :  ");
        scanf("%d",&n);
        int a[n][3];
        int i;
        int j;
        int k;
        for( i=0; i<n; i++)
        {
            for(j=0; j<3; j++)
            {
                scanf("%d",&a[i][j]);
            }
            
        }
        
        for(i=0; i<n; i++)
        {
            if(a[i][2]<41)
            {
               k = a[i][0]*a[i][1]*a[i][2];
                printf("%d\n",k);
            }
            else
            break;
           
        }
    		return 0;
        
    }
    
  • + 0 comments

    Kudos to the author of this question for writing nice code.

  • + 0 comments

    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) { /** * Return the volume of the box */ return (b.length * b.width * b.height); }

    int is_lower_than_max_height(box b) { /** * Return 1 if the box's height is lower than MAX_HEIGHT and 0 otherwise */ return (b.height < MAX_HEIGHT? 1: 0); }

  • + 0 comments

    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) { /** * Return the volume of the box */ return b.length*b.width*b.height; }

    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<41) { return 1; } else { return 0; } }