Area of squares formed by joining mid points repeatedly in C Program?
Suppose we have one square whose side is ‘a’. We will make more squares by attaching the mid-points of the squares repeatedly. The number of repetition is n times. We have to find the area of nth square.
As the side of the outer square is ‘a’, then area is
Now using Pythagorean theorem, we can get the area of the second rectangle is −
Similarly, area of 3rd square is −
Using this we can understand that the area of nth square is −
Example
#include <iostream>
#include <cmath>
using namespace std;
float area(float a, float n) {
if (a < 0 ) //if the value is negative it is invalid
return -1;
float area = (a*a) / pow(2, n-1);
return area;
}
int main() {
float a = 20.0, n = 10.0;
cout << "Area : " << area(a, n);
}
Output
Area : 0.78125
Related Articles
- Area of squares formed by joining midpoints repeatedly in C?
- Fill in the blanks to make the following statements correct :The figure formed by joining the mid-points of consecutive sides of a quadrilateral is …....
- Find the area of the triangle formed by joining the mid-points of the sides of the triangle whose vertices are $(0, -1), (2, 1)$ and $(0, 3)$. Find the ratio of this area to the area of the given triangle.
- Fill in the blanks to make the following statements correct :The triangle formed by joining the mid-points of the sides of an isosceles triangle is …...
- Fill in the blanks to make the following statements correct :The triangle formed by joining the mid-points of the sides of a right triangle is …....
- $ABCD$ is a kite having $AB = AD$ and $BC = CD$. Prove that the figure formed by joining the mid-points of the sides, in order, is a rectangle.
- Show that the mid-point of the line segment joining the points $(5, 7)$ and $(3, 9)$ is also the mid-point of the line segment joining the points $(8, 6)$ and $(0, 10)$.
- Find Corners of Rectangle using mid points in C++
- Find the mid point of the line segment joining the points $( -5,\ 7)$ and $( -1,\ 3)$.
- Find the mid point of the line segment joining the points $( 0,\ 0)$ and $( -2,\ -4)$.
- Find the mid point of the line segment joining the points $( 0,\ 0)$ and $( 2,\ 2)$.
- Minimize the sum of squares of sum of N/2 paired formed by N numbers in C++
- In a triangle $\triangle ABC, \angle A = 50^o, \angle B = 60^o$ and $\angle C = 70^o$. Find the measures of the angles of the triangle formed by joining the mid-points of the sides of this triangle.
- Maximum length cycle that can be formed by joining two nodes of a binary tree in C++
- Find the mid-point of the line segment joining the points $A ( -2,\ 8)$ and $B ( -6,\ -4)$.
Kickstart Your Career
Get certified by completing the course
Get Started