📜  求半圆面积和周长的程序

📅  最后修改于: 2021-10-23 08:13:22             🧑  作者: Mango

给定半圆的半径为 r,任务是找出该半圆的面积和周长。
例子:

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

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

方法:
在数学中,半圆是形成半圆的点的一维轨迹。半圆的面积是构成它的圆面积的一半。任何直径的圆都将其切成两个相等的半圆。

下面是上述方法的实现:

C++
// C++ program to find the
// Area and Perimeter of a Semicircle
 
#include 
using namespace std;
 
// Function for calculating the area
float area(float r)
{
    // Formula for finding the area
    return (0.5)*(3.14)*(r * r);
}
 
// Function for calculating the perimeter
float perimeter(float r)
{
    // Formula for finding the perimeter
    return (3.14)*(r);
}
 
// driver code
int main()
{
 
    // Get the radius
    int r = 10;
 
    // Find the area
    cout << "The Area of Semicircle: "
         << area(r) << endl;
 
    // Find the perimeter
    cout << "The Perimeter of Semicircle: "
         << perimeter(r) << endl;
 
    return 0;
}


C
// C program to find the
// Area and Perimeter of a Semicircle
 
#include 
 
// Function for calculating the area
float area(float r)
{
    // Formula for finding the area
    return (0.5)*(3.14)*(r * r);
}
 
// Function for calculating the perimeter
float perimeter(float r)
{
    // Formula for finding the perimeter
    return (3.14)*(r);
}
 
// driver code
int main()
{
 
    // Get the radius
    float r = 10;
 
    // Find the area
    printf("The Area of Semicircle: %f\n",
        area(r));
 
    // Find the perimeter
    printf("The Perimeter of Semicircle: %f\n",
        perimeter(r));
    return 0;
}


Java
// Java program to find the
// Area and Perimeter of a Semicircle
 
import java.io.*;
 
class GFG {
 
// Function for calculating the area
static float area(float r)
{
    // Formula for finding the area
    return (float)((0.5)*(3.14)*(r * r));
}
 
// Function for calculating the perimeter
static float perimeter(float r)
{
    // Formula for finding the perimeter
    return (float)((3.14)*(r));
}
 
// driver code
 
    public static void main (String[] args) {
    // Get the radius
    float r = 10;
 
    // Find the area
    System.out.println("The Area of Semicircle: "+
        area(r));
 
    // Find the perimeter
    System.out.println("The Perimeter of Semicircle:"+
        +perimeter(r));
    }
}
 // This code is contributed
// by anuj_67..


Python3
# Python3 program to find the
# Area and Perimeter of a Semicircle
 
# Function for calculating the area
def area(r):
     
    # Formula for finding the area
    return (0.5)*(3.14)*(r * r)
 
#Function for calculating the perimeter
def perimeter(r):
     
    #Formula for finding the perimeter
    return (3.14)*(r)
 
# driver code
if __name__=='__main__':
    # Get the radius
    r = 10
 
    # Find the area
    print ("The Area of Semicircle: "
           ,area(r))
 
    # Find the perimeter
    print ("The Perimeter of Semicircle: "
           ,perimeter(r))
            
# This code is contributed by
# SURENDRA_GANGWAR


C#
// C# program to find the
// Area and Perimeter of a Semicircle
using System;
 
class GFG {
 
// Function for calculating the area
static float area(float r)
{
    // Formula for finding the area
    return (float)((0.5)*(3.14)*(r * r));
}
 
// Function for calculating the perimeter
static float perimeter(float r)
{
    // Formula for finding the perimeter
    return (float)((3.14)*(r));
}
 
// Driver Code
public static void Main()
{
    // Get the radius
    float r = 10;
     
    // Find the area
    Console.WriteLine("The Area of Semicircle: " +
                                         area(r));
     
    // Find the perimeter
    Console.WriteLine("The Perimeter of Semicircle:" +
                                        perimeter(r));
}
}
 
// This code is contributed
// by Akanksha Rai(Abby_akku)


PHP


Javascript


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