- 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

Given the task is to find the maximum number of squares having side ‘a’ that can fit inside a give right angle isosceles triangle with base of ‘s’(An isosceles triangle has at least 2 equal sides).

Let’s now understand what we have to do using an example:

s=5, a=1

10

**Explanation** − The number of squares in the base can be calculated by dividing s by a and subtracting 1. So the number of squares in base = 5/1 – 1 = 4.

Similarly when the bottom 4 squares are placed then we get a new isosceles triangle with base (s-a) and then we repeat the same procedure and get 3 squares and so on until a single square is placed at the top.

s=7, a=2

3

To find the maximum number of squares we will have to start from the base of the triangle and find out the number of squares.

To find the number of squares we will divide the base s by the side of the square a and subtract 1 from it = s/a – 1.

Then it will leave us another isosceles triangle with base (s - a) which will accommodate one less square than the previous row below it which we can calculate in the following way −

Squares in next row = (s - a)/a – 1 = (s/a – a/a) – 1= s/a - 1 - 1 = s/a – 2 = one square less than the previous row.

The number of squares keep decreasing until it reaches 1, therefore we have to only find the number of squares in the base row and use the formula of adding natural numbers to find the final sum which is −

(n) * (n + 1) / 2

In this case the formula becomes − ((s / a) – 1) * (s / a) / 2

#include<bits/stdc++.h> using namespace std; int Max(int s, int a){ //formula for calculating maximum squares return ((s / a) - 1) * (s / a) / 2; } //Main function int main(){ int s = 5, a = 1; cout <<"Maximum squares possible are: "<<Max(s,a); return 0; }

10

- Related Questions & Answers
- Maximum number of 2×2 squares that can be fit inside a right isosceles triangle in C
- Maximum sum of a path in a Right Number Triangle in C++
- Find other two sides of a right angle triangle in C++
- Find other two sides and angles of a right angle triangle in C++
- Biggest Reuleaux Triangle within a Square which is inscribed within a Right angle Triangle in C?
- Biggest Reuleaux Triangle within a Square which is inscribed within a Right angle Triangle?
- Find the altitude and area of an isosceles triangle in C++
- Maximum Number of Events That Can Be Attended in C++
- Maximum number of candies that can be bought in C
- Maximum number of threads that can be created within a process in C
- Program to count number of isosceles triangle from colored vertex regular polygon in Python
- Find maximum number that can be formed using digits of a given number in C++
- Python program to find angle between mid-point and base of a right angled triangle
- Maximum number of segments that can contain the given points in C++
- Area of Incircle of a Right Angled Triangle in C Program?

Advertisements