

- 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
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 Questions & Answers
- Area of squares formed by joining midpoints repeatedly in C?
- Find Corners of Rectangle using mid points in C++
- Maximum length cycle that can be formed by joining two nodes of a binary tree in C++
- Minimize the sum of squares of sum of N/2 paired formed by N numbers in C++
- Area of triangle formed by the axes of co-ordinates and a given straight line?
- Program to find the mid-point of a line in C++
- Maximum sum after repeatedly dividing N by a divisor in C++
- Maximum Score Words Formed by Letters in C++
- Mid-Square hashing in C++.
- Program for Area Of Square in C++
- Determine the number of squares of unit area that a line will pass through in C++?
- Recursive sum of digits of a number formed by repeated appends in C++
- Sum of squares of first n natural numbers in C Program?
- C++ Program to Repeatedly Search the Same Text (such as Bible by building a Data Structure)
- Program for Surface area of Dodecahedron in C++
Advertisements