- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion

# Maximum given sized rectangles that can be cut out of a sheet of paper in C

We are given the dimensions of the sheet of paper, it’s Length L, and Breadth B. Also, we are given the dimensions of a small rectangle, it’s length l, and breadth b. The goal is to find the maximum number of smaller rectangles that can be cut out of a sheet of paper.

We will do following steps −

Firstly, we will take horizontal alignment, lengths L and l of sheet and rectangle respectively. Start aligning the L by l and B by b and count the rectangles.

Then also do the same in vertical alignments. Count again. Return the maximum value of count.

Let us understand with an example.

**Input**

Sheet L=18, B=6 Rectangle l=4, b=3

**Output**

Maximum rectangles: 8

**Explanation**

Horizontal 18/4=4 6/3=2 2*4=8 rectangles possible Vertical 18/3=6 6/4=1 6*1=6 rectangles possible Maximum rectangles here is 8

**Input**

Sheet L=10, B=6 Rectangle l=4, b=2

**Output**

Maximum rectangles: 6

**Explanation**

Horizontal 10/4=2 6/2=3 2*3=6 rectangles possible Vertical 10/2=5 6/4=1 5*1=5 rectangles possible Maximum rectangles here is 6

## Approach used in the below program is as follows

The variables Length and Breadth are used to store dimensions of sheet.

The variables len and bre are used to store dimensions of rectangle.

Function maxRectangles (int L, int B, int l, int b) takes dimensions of sheet and rectangle and returns the maximum number of rectangles possible.

Variables numh and numv are used to store the number of rectangles that can be cut horizontally and vertically.

For horizontally, divide cols=L/l and rows=B/b, rectangles possible, numh=cols*rows.

For vertically, divide cols=L/b and rows=B/l, rectangles possible, numv=cols*rows.

Return maximum value as result obtained in above two steps numh or numv.

## Example

#include <stdio.h> int maxRectangles (int L, int B, int l, int b){ int numh = 0, numv = 0; // Cut rectangles horizontally if possible if (l <= L && b <= B){ // One rectangle is a single cell int cols = B / b; int rows = L / l; // Total rectangles = total cells numh = rows * cols; } // Cut rectangles vertically if possible if (l <= B && b <= L){ int cols = L / b; int rows = B / l; numv = rows * cols; } // Return the maximum possible rectangles return numh>numv?numh:numv; } // Driver code int main (){ int Length = 18; int Breadth =6; int len = 4, bre = 3; printf("Maximum rectangles: %d",maxRectangles(Length,Breadth,len,bre)); return 0; }

## Output

If we run the above code it will generate the following output −

Maximum given sized rectangles that can be cut out of a sheet of paper: 8

- Related Articles
- Maximum of smallest possible area that can get with exactly k cut of given rectangular in C++
- Find maximum number that can be formed using digits of a given number in C++
- C++ program to find out the maximum number of cells that can be illuminated
- What should be the side of the squares which has to be cut out from the corners of square sheet of side 10 cm, so that the volume of the open box formed by the sheet should be maximum ?
- C++ Program to find out the maximum amount of score that can be decreased from a graph
- Maximum Number of Events That Can Be Attended in C++
- Maximum number of candies that can be bought in C
- Maximum number of parallelograms that can be made using the given length of line segments in C++
- Problem to Find Out the Maximum Number of Coins that Can be Collected in Python
- C++ Program to find out the maximum amount of money that can be made from selling cars
- C++ Program to find out the maximum amount of profit that can be achieved from selling wheat
- Maximum number of threads that can be created within a process in C
- Maximum number of segments that can contain the given points in C++
- Maximum elements which can be crossed using given units of a and b in C++
- Maximum litres of water that can be bought with N Rupees in C++