Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
A rectangle plot of I*j metres is left and we have a*a metres square blocks left.An architect planned to use square blocks,what is the required number of square to cover rectangle plot and if required we can cover more rectangular plot but should not break squares.

What I have tried:

I have tried by calculating rectangular area and compared with square area if square area is I continued my process and counted square blocks and in certain conditions I added some other square blocks to cover rectangular plot.
Posted
Updated 27-Sep-17 1:41am
Comments
Laxmidhar tatwa technologies 27-Sep-17 7:34am    
It is possible when the Rectangle Length and breadth divisible by side of square

Area isn't that important, rectangle i,j dimensions are important.
You know, if you are lucky a divides exactly i, so you need exactly (i/a) (integer division) squares int the i direction.
On the other hand, if you're not so lucky then there is a remainder in the division and you need one more square, namely (i/a + 1) squares in the i direction. You can produce a similar argument for the j direction and easily figure out how many squares you need.
 
Share this answer
 
This looks like homework, so no code:
Start by calculating the biggest square you can fit in your current rectangle, then look at what is left. That will be a rectangular area, so you can use the same processing to generate the next square.
If you know the minimum size of a square, you can compare that against the sizes of the rectangle to decide if you should just be exceeding the rectangle to fit in a square.
 
Share this answer
 
Quote:
What is the method to solve a problem like this in c.

The same as with any other programming language.

Take a sheet of paper and a pencil and solve the problem by hand and find the maths.
You solved the problem by following a procedure, that procedure is your algorithm. You need to write down the steps in a mechanical manner (computer like). The program will follow those steps.

As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.

We do not do your HomeWork.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900