📜  计算半球体积和表面积的程序

📅  最后修改于: 2021-04-29 07:48:02             🧑  作者: Mango

计算半球的体积和表面积。
半球:
在几何中,它恰好是球体的一半。我们可以找到许多半球的现实例子,例如我们的地球可以分为南半球和北半球两个半球。

4

半球的体积:半球的体积不过是半球所占据的空间量。它也定义为被半球边界包围的三维空间的数量。
表面积:精确覆盖半球表面的平方单位的数量。
表面积= 2 \pi r^2
音量= \frac{2 \pi r^2}{3}
例子 :

Input :  Radius = 7
Output : Volume = 718.378
         Surface Area = 307.876

Input :  Radius = 11
Output : Volume = 2787.64
         Surface Area = 760.265
C++
// CPP Program to calculate volume and
// and surface area of a Hemisphere.
#include 
using namespace std;
// Initializing value of pi
#define pi 3.141592653589793
 
// Function to calculate volume
void volume(float r)
{
    float volume = float(2 * pi * pow(r, 3)) / float(3);
    cout << "Volume = " << volume << endl;
}
// Function to calculate surface area
void surface_area(float r)
{
    float s_area = 2 * pi * pow(r, 2);
    cout << "Surface Area = " << s_area << endl;
}
 
// Driver program
int main()
{
    float r = 11;
    volume(r);
    surface_area(r);
    return 0;
}


Java
// Java Program to calculate volume and
// and surface area of a Hemisphere.
import java.util.*;
import java.lang.*;
 
public class GfG{
     
    // Initializing value of pi
    private static final float pi = (float) 3.141592653589793;
 
    // Function to calculate volume
    public static void volume(float r)
    {
        float volume = (float)(2 * pi *(float) Math.pow(r, 3))
                                                    / (float)(3);
        System.out.println("Volume = " + volume);
    }
    // Function to calculate surface area
    public static void surface_area(float r)
    {
        float s_area = (float)2 * pi * (float)Math.pow(r, 2);
        System.out.println("Surface Area = " + s_area);
    }
     
    // Driver function
    public static void main(String argc[]){
        float r = 11;
        volume(r);
        surface_area(r);
    }
     
}
/* This code is contributed by Sagar Shukla */


Python
# Python code Program to calculate volume and
# and surface area of a Hemisphere.
import math
 
# Function to calculate volume
def volume(r):
    volume = 2 * math.pi * math.pow(r, 3) / 3
    print("Volume = ", '%.4f' %volume)
 
# Function to calculate surface area
def surface_area(r):
    s_area = 2 * math.pi * math.pow(r, 2)
    print("Surface Area = ", '%.4f' %s_area)
     
# Driver code
r = 11
volume(r)
surface_area(r)


C#
// C# Program to calculate volume and
// and surface area of a Hemisphere.
using System;
 
public class GfG{
     
    // Initializing value of pi
    private static float pi = (float) 3.141592653589793;
 
    // Function to calculate volume
    public static void volume(float r)
    {
        float volume = (float)(2 * pi *(float) Math.Pow(r, 3))
                                                / (float)(3);
        Console.WriteLine("Volume = " + volume);
    }
     
    // Function to calculate surface area
    public static void surface_area(float r)
    {
        float s_area = (float)2 * pi * (float)Math.Pow(r, 2);
        Console.WriteLine("Surface Area = " + s_area);
    }
     
    // Driver function
    public static void Main()
    {
        float r = 11;
        volume(r);
        surface_area(r);
    }
     
}
 
/* This code is contributed by vt_m */


PHP


Javascript


输出
Volume = 2787.64
Surface Area = 760.265