- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# 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 Questions & Answers
- Maximum of smallest possible area that can get with exactly k cut of given rectangular in C++
- C++ program to find out the maximum number of cells that can be illuminated
- Find maximum number that can be formed using digits of a given number in C++
- Maximum Number of Events That Can Be Attended in C++
- Maximum number of candies that can be bought in C
- C++ Program to find out the maximum amount of score that can be decreased from a graph
- 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
- Maximum number of threads that can be created within a process in C
- 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 segments that can contain the given points in C++
- Maximum litres of water that can be bought with N Rupees in C++
- Maximum number of people that can be killed with strength P in C++
- C++ program to find out the number of coordinate pairs that can be made