of square that can be accommodated : %d",numofSquares(base)) Return the calculation as the number of squares. The integer variable base is used to store the Base of triangle.įunction numofSquares(int b) is used to count the number of squares that triangle with base b can accommodate.Īt first b=b-2 −extra space from corner endsĪccording to formula, b=floor(b/2), this new b can have b*(b+1)/2 squares of side 2. Use formula of Ap = b*(b+1)/2….where new b=b-2Įxplanation base 12>2, squares 10/2=5, new base 12-2=10īase 10>2, squares 8/2=4, new base 10-2=8Įxplanation base 5>2, squares 3/2=1, new base 5-2=3īase 1>2 X Total squares=1 Approach used in the below program is as follows Same will be the case with height ( ag ). No we have to divide remaining base gd( or height ag) by 2 to count no. So first we will always need extra 2 units of length for these triangles. From the corner ends ‘a’ and ‘d’, triangles aib and cde would never contribute to any square. The given triangle of height ag and base gd has 3 squares of side 2 each. Refer to the below figure to understand the problem The sides base or height (both equal) are taken as input. The goal is to find the maximum number of squares that can fit into this right isosceles triangle of side 2 sq units. Right triangle is the one which has height(ag in fig.) and base (dg in fig.) perpendicular to each other. Isosceles triangle is the one which has two sides of equal length.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |