Q:

Program to find the area and perimeter of the semicircle

0

In this article, we will discuss the program to find the area and perimeter of semicircle in different programming languages.

But before writing the programs, let's first see a brief description of the semicircle and the formulae to find its area and perimeter.

Semicircle

When a line passes through the center and touches the two ends of the circle, then a semicircle is formed. The diameter of a circle divides it into two halves that are referred to as semicircles. A semicircle is the half part of a circle.

Area of semicircle

The area of semicircle is equal to half of the area of a circle. When we divide the area of a circle by 2, we will get the area of the semicircle.

The area of a circle is πr2. So, the area of semicircle will be -

Area of semicircle =1/2( πr2)

The perimeter of a semicircle is equivalent to the sum of diameter and half of the circumference of a circle.

The formula for perimeter of the circle can be πd or 2πr (where 'd' is diameter and 'r' is the radius). So, the formula to calculate the perimeter of a semicircle is -

 

Perimeter of a semicircle = 1/2 (?d) + d   

or,  

Perimeter of a semicircle = (?r + d)   

or,  

Perimeter of a semicircle = (?r + 2r)   

or,  

Perimeter of a semicircle = r(? + 2)  

(where 'd' is diameter and 'r' is radius)  

Now, let's see the programs to find the area and perimeter of the semicircle.

Programs to find the area and perimeter of the semicircle

In the programs, we are using the formulae given below -

 

Area of semicircle = ? x r  

Perimeter of semicircle = r x (? + 2)   

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program: Write a program to find the area and perimeter of semicircle in C language.

#include <stdio.h>  
  
float area(float radius)  
{  
    return (0.5)*(3.14)*(radius * radius);  
}  
  
float perimeter(float radius)  
{  
    return radius * (3.14 + 2);  
}  
  
int main()  
{  
float r;  
printf("Enter the radius: ");  
scanf("%f", &r);  
    printf("The Area of Semicircle: %f\n", area(r));  
    printf("The Perimeter of Semicircle: %f\n", perimeter(r));  
    return 0;  
}  

Output:

 

Program: Write a program to find the area and perimeter of semicircle in C++ language.

#include <iostream>  
using namespace std;  
float area(float radius) {  
   return (0.5)*(3.14)*(radius * radius);  
}  
float perimeter(float radius) {  
   return radius * (3.14 + 2);  
}  
int main(){  
   float r;  
   cout<<"Enter the radius: ";  
   cin >>r;  
   cout<<"The area of semicircle is: "<<area(r)<<endl;  
   cout<<"The perimeter of semicircle is: "<<perimeter(r)<<endl;  
   return 0;  
}  

Output:

 

Program: Write a program to find the area and perimeter of semicircle in python language.

def area(radius):  
    return (0.5) * (3.14) * (radius * radius)  
def perimeter(radius):  
      return radius * (3.14 + 2);  
  
r = int(input('Enter the radius: '))  
print ("The Area of Semicircle: ", area(r))  
print ("The Perimeter of Semicircle: ", perimeter(r))  

Output:

After the execution of the above code, and after entering the value of the radius, the output will be -

 

Program: Write a program to find the area and perimeter of semicircle in Java.

import java.util.*;  
import java.lang.*;  
  
public class Semicircle{  
    static float area(float radius)  
{  
    return (float)((0.5)*(3.14)*(radius * radius));  
}  
static float perimeter(float radius)  
{  
    return (float)(radius * (3.14 + 2));  
}  
  
    public static void main(String argc[])  
    {  
        System.out.println("Enter the radius: ");  
        Scanner sc = new Scanner(System.in);  
        int r = sc.nextInt();  
    System.out.println("The Area of Semicircle: " + area(r));  
    System.out.println("The Perimeter of Semicircle: " + perimeter(r));  
    }  
}  

Output:

 

Program: Write a program to find the area and perimeter of semicircle in JavaScript.

<!DOCTYPE html>  
<html>  
   <body>  
<script>  
    function area(radius) {  
        return ((0.5) * (3.14) * (radius * radius));  
    }  
    function perimeter(radius) {  
        return (radius * (3.14 + 2));  
    }  
        let r = prompt("Enter the radius: ");  
        document.write("The Area of Semicircle is: " + area(r) + "<br/>");  
        document.write("The Perimeter of Semicircle is: " + perimeter(r) + "<br/>");  
</script>  
  
</body>  
</html>  

Output:

After the execution of the above code, the output will be 

After entering the value and clicking on OK, the output will be -

 

Program: Write a program to find the area and perimeter of semicircle in C#.

using System;  
public class Jtp  
{  
static float area(float radius)  
{  
    return (float)((0.5)*(3.14)*(radius * radius));  
}  
  
static float perimeter(float radius)  
{  
    return (float)(radius * (3.14 + 2));  
}  
  
  public static void Main ()  
  {  
    int r;  
    Console.Write ("Enter the radius: ");  
    r = Convert.ToInt32 (Console.ReadLine ());  
    Console.WriteLine("The Area of Semicircle is: " + area(r));  
    Console.WriteLine("The Perimeter of Semicircle is: " + perimeter(r));  
  }  
}  

Output:

 

Program: Write a program to find the area and perimeter of semicircle in PHP.

<?php  
function area($radius)  
{  
    return (0.5) * (3.14) * ($radius * $radius);  
}  
function perimeter($radius)  
{  
    return ($radius * (3.14 + 2));  
}  
$r = 10;  
echo "The value of radius is: ", $r , "<br>" ;  
echo "The Area of Semicircle is: ", area($r) , "<br>" ;  
echo "The Perimeter of Semicircle is: ", perimeter($r);  
?>  

Output:

So, that's all about the article. Here, we have discussed the programs to find the area and perimeter of semicircle in CC++JavaC#PHPpython, and JavaScript. Hope you find the article helpful and informative.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now