Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Area of the circle that has a square and a circle inscribed in it
Next article icon

Area of the circle that has a square and a circle inscribed in it

Last Updated : 05 Dec, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Given the side of a square that is kept inside a circle. It keeps expanding until all four of its vertices touch the circumference of the circle. Another smaller circle is kept inside the square now and it keeps expanding until its circumference touches all four sides of the square. The outer and the inner circle form a ring. Find the area of this shaded part as shown in the image below. 

Examples: 

Input: a = 3 
Output: 7.06858

Input: a = 4 
Output: 12.566371 


Approach: 
 


From the above figure, R = a / sqrt(2) can be derived where a is the side length of the square. The area of the outer circle is (pi * R * R).
Let s1 be the area of the outer circle (pi * R * R) and s2 be the area of the inner circle (pi * r * r). Then the area of the ring is s1 - s2.

Below is the implementation of the above approach:

C++
// C++ implementation of the approach #include <bits/stdc++.h> using namespace std;  // Function to return the required area float getArea(int a) {      // Calculate the area     float area = (M_PI * a * a) / 4.0;     return area; }  // Driver code int main() {     int a = 3;      cout << getArea(a);      return 0; } 
Java
// Java implementation of the approach public class GFG {      // Function to return the required area     static float getArea(int a)     {          // Calculate the area         float area = (float)(Math.PI * a * a) / 4;         return area;     }      // Driver code     public static void main(String args[])     {         int a = 3;         System.out.println(getArea(a));     } } 
Python3
# Python3 implementation of the approach import math   # Function to return the required area def getArea(a):          # Calculate the area     area = (math.pi * a * a) / 4     return area      # Driver code a = 3 print('{0:.6f}'.format(getArea(a))) 
C#
// C# implementation of the approach using System;  class GFG  {      // Function to return the required area     static float getArea(int a)     {          // Calculate the area         float area = (float)(Math.PI * a * a) / 4;         return area;     }      // Driver code     public static void Main()     {         int a = 3;         Console.Write(getArea(a));     } }  // This code is contributed by mohit kumar 29 
JavaScript
<script>  // Javascript implementation of the approach  // Function to return the required area function getArea(a) {          // Calculate the area     var area = (Math.PI * a * a) / 4;     return area; }  // Driver Code  var a = 3;  document.write(getArea(a));  // This code is contributed by Kirti      </script>                     

Output
7.06858

Time Complexity: O(1)
Auxiliary Space: O(1)


Next Article
Area of the circle that has a square and a circle inscribed in it

B

Bhargav_Thota
Improve
Article Tags :
  • Java
  • Analysis of Algorithms
  • Mathematical
  • Geometric
  • Python
  • C++ Programs
  • Java Programs
  • C++
  • Aptitude
  • Computer Science Fundamentals
  • DSA
Practice Tags :
  • CPP
  • Geometric
  • Java
  • Mathematical
  • python

Similar Reads

    Area of a square inscribed in a circle which is inscribed in a hexagon
    Given a regular hexagon with side A, which inscribes a circle of radius r, which in turn inscribes a square of side a.The task is to find the area of this square.Examples: Input : A = 5 Output : 37.5 Input : A = 8 Output : 96 Approach: We know the radius of the circle inscribed within the hexagon is
    4 min read
    Area of a circle inscribed in a rectangle which is inscribed in a semicircle
    Given a semicircle with radius R, which inscribes a rectangle of length L and breadth B, which in turn inscribes a circle of radius r. The task is to find the area of the circle with radius r.Examples: Input : R = 2 Output : 1.57 Input : R = 5 Output : 9.8125 Approach: We know the biggest rectangle
    4 min read
    Java Program to Calculate and Display Area of a Circle
    Given a radius of the circle, write a java program to calculate and display the area of the circle. (Take ∏=3.142) Example Input : radius= 5 Output: Area of circle is : 78.55 Input : radius= 8 Output: Area of circle is : 201.08As we know to calculate the area of a circle, the radius of the circle mu
    1 min read
    Java Program to Find the Area of a Circle Given the Radius
    A circle is a simple shape consisting of all the points in the plane that are equidistant from a point known as the center of the circle. In this article, we will learn how to find the area of the circle. Terminology: Area: A quantity that represents the extent of a 2-dimensional figure or shape in
    2 min read
    Biggest Reuleaux Triangle inscribed within a square inscribed in a semicircle
    Given here is a semicircle of radius r which inscribes a square which in turn inscribes a reuleaux triangle. The task is to find the maximum possible area of this reuleaux triangle.Examples: Input : x = 5 Output : 14.0954 Input : x = 8 Output : 36.0842 Approach:We know, the side of the square inscri
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences