Horje
Program to find the Area and Perimeter of a Semicircle

Given the radius of the semicircle as r, the task is to find out the Area and Perimeter of that semicircle.
Examples: 
 

Input: r = 10
Output: Area = 157.00, Perimeter = 31.4

Input: r = 25
Output: Area =981.250000, Perimeter = 78.500000

 

Approach: 
In mathematics, a semicircle is a one-dimensional locus of points that forms half of a circle. The area of a semicircle is half the area of the circle from which it is made. Any diameter of a circle cuts it into two equal semicircles.
 

 

Area of Semi-Circle = 1?2 * ? *r2 
Perimeter of Semi-Circle = ? *r 
where “r” is the radius of the semicircle. 
 

Below is the implementation of the above approach:
 

C++

<?php
// PHP program to find the
// Area and Perimeter of a Semicircle
 
// Function for calculating the area
function area($r)
{
    // Formula for finding the area
    return (0.5) * (3.14) * ($r * $r);
}
 
// Function for calculating
// the perimeter
function perimeter($r)
{
    // Formula for finding
    // the perimeter
    return (3.14) * ($r);
}
 
// Driver code
 
// Get the radius
$r = 10;
 
// Find the area
echo "The Area of Semicircle: ",
    area($r),"\n" ;
 
// Find the perimeter
echo "The Perimeter of Semicircle: ",
    perimeter($r),"\n" ;
 
// This code is contributed
// by ANKITRAI1
?>

Javascript

<script>
// javascript program to find the
// Area and Perimeter of a Semicircle
 
// Function for calculating the area
    function area(r) {
        // Formula for finding the area
        return  ((0.5) * (3.14) * (r * r));
    }
 
    // Function for calculating the perimeter
    function perimeter(r) {
        // Formula for finding the perimeter
        return  ((3.14) * (r));
    }
 
    // driver code
 
     
        // Get the radius
        var r = 10;
 
        // Find the area
        document.write("The Area of Semicircle: " + area(r).toFixed(6)+"<br/>");
 
        // Find the perimeter
        document.write("The Perimeter of Semicircle: " +
        perimeter(r).toFixed(6)+"<br/>");
 
// This code contributed by gauravrajput1
 
</script>

Output: 

The Area of Semicircle: 157.000000
The Perimeter of Semicircle: 31.400000

 

Time Complexity: O(1), since there is no loop or recursion.

Auxiliary Space: O(1), since no extra space has been taken.




Reffered: https://www.geeksforgeeks.org


Mathematical

Related
Sum of Fibonacci numbers at even indexes upto N terms Sum of Fibonacci numbers at even indexes upto N terms
Check if the frequency of all the digits in a number is same Check if the frequency of all the digits in a number is same
Maximum difference elements that can added to a set Maximum difference elements that can added to a set
Largest number divisible by 90 that can be made using 0 and 5 Largest number divisible by 90 that can be made using 0 and 5
Count number of integers less than or equal to N which has exactly 9 divisors Count number of integers less than or equal to N which has exactly 9 divisors

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
9