Home > Backend Development > C++ > What is the area of ​​the square formed by repeatedly connecting midpoints in a C program?

What is the area of ​​the square formed by repeatedly connecting midpoints in a C program?

WBOY
Release: 2023-09-01 08:01:07
forward
1398 people have browsed it

Suppose we have a square with side length "a". We will make more squares by repeatedly connecting the midpoints of the squares. The number of repetitions is n times. We have to find the area of ​​the nth square.

What is the area of ​​the square formed by repeatedly connecting midpoints in a C program?

Since the side length of the outer square is "a", the area is

What is the area of ​​the square formed by repeatedly connecting midpoints in a C program?

Now use Pythagoras According to Sri Lanka's theorem, we can get that the area of ​​the second rectangle is -

Similarly, the area of ​​the third rd square is -

Using this we can know that the area of ​​the nth square is-

What is the area of ​​the square formed by repeatedly connecting midpoints in a C program?

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);
}
Copy after login

Output

Area : 0.78125
Copy after login

The above is the detailed content of What is the area of ​​the square formed by repeatedly connecting midpoints in a C program?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template