Area of a leaf inside a square - GeeksforGeeks

06 Jun, 2021
Given an integer a as the side of the square ABCD. The task is to find the area of the leaf AECFA inside the square as shown below:
Examples: 
Input: a = 7 Output: 28
Input: a = 21 Output: 252 
Approach: To calculate the area of the leaf, first find the area of the half leaf AECA, which can be given as:  
Area of half leaf = Area of quadrant AECDA – Area of right triangle ACD. Thus, Area of half leaf = ( PI * a * a / 4 ) – a * a / 2 where PI = 22 / 7 and a is the side of the square. Hence, the area of full leaf will be ( PI * a * a / 2 ) – a * a On taking a * a common we get, Area of leaf = a * a ( PI / 2 – 1 )
Below is the implementation of the above approach:  
C
Java
Python3
C#
PHP
Javascript
// C program to find the area of// leaf inside a square#include <stdio.h>#define PI 3.14159265 // Function to find area of// leaffloat area_leaf(float a){    return (a * a * (PI / 2 - 1));} // Driver codeint main(){    float a = 7;    printf("%f",           area_leaf(a));    return 0;}
// Java code to find the area of// leaf inside a squareimport java.lang.*; class GFG {     static double PI = 3.14159265;     // Function to find the area of    // leaf    public static double area_leaf(double a)    {        return (a * a * (PI / 2 - 1));    }     // Driver code    public static void main(String[] args)    {        double a = 7;        System.out.println(area_leaf(a));    }}
# Python3 code to find the area of leaf# inside a squarePI = 3.14159265     # Function to find the area of# leafdef area_leaf( a ):    return ( a * a * ( PI / 2 - 1 ) )     # Driver codea = 7print(area_leaf( a ))
// C# code to find the area of// leaf// inside squareusing System; class GFG {    static double PI = 3.14159265;     // Function to find the area of    // leaf    public static double area_leaf(double a)    {        return (a * a * (PI / 2 - 1));    }     // Driver code    public static void Main()    {        double a = 7;        Console.Write(area_leaf(a));    }}
<?php// PHP program to find the// area of leaf// inside a square$PI = 3.14159265; // Function to find area of// leaffunction area_leaf( $a ){    global $PI;    return ( $a * $a * ( $PI / 2 - 1 ) );} // Driver code$a = 7; echo(area_leaf( $a ));?>
<script> // Javascript program to find the area of// leaf inside a squareconst PI = 3.14159265; // Function to find area of// leaffunction area_leaf(a){    return(a * a * (PI / 2 - 1));} // Driver codelet a = 7; document.write(Math.round(area_leaf(a))); // This code is contributed by souravmahato348 </script>
28
 
souravmahato348
Aptitude
Geometric
Mathematical
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Puzzle | How much money did the man have before entering the bank?
Order and Ranking Questions & Answers
C | C Quiz - 113 | Question 1
Program to find Surface Area and Volume of Octagonal Prism
Aptitude | Syllogism | Question 3
How to check if a given point lies inside or outside a polygon?
Closest Pair of Points using Divide and Conquer algorithm
Program for distance between two points on earth
How to check if two given line segments intersect?
Convex Hull | Set 1 (Jarvis's Algorithm or Wrapping)