📜  计算球体的体积和表面积

📅  最后修改于: 2021-04-26 09:15:50             🧑  作者: Mango

给定球体半径,计算球体的体积和表面积。
领域:
就像一个在几何上是二维对象的圆一样,球在数学上被定义为与给定点都在相同距离r处但在三维空间中的一组点。该距离r是球体的半径,给定点是球体的中心。
对于给定的表面积,球是体积最大的一个固体。这就是为什么它在自然界出现如此之多的原因,例如水滴,气泡和行星等。
球体体积:
恰好填充一个球体的立方单位数或该球体的存储容量。我们可以使用以下公式计算球体的体积:

球体表面积:
球体对象的表面积是球体表面占据的总面积的度量。我们可以使用以下公式计算球体的体积:

例子 :

Input  : Radius Of Sphere = 5
Output : Volume    Of    Sphere :  523.5987755982989
         Surface Area Of Sphere :  314.1592653589793
Explanation:
         Volume =( 4/3 ) * 3.14159 * 5 * 5 * 5 = 523.598
         Surface Area = 4 * 3.14159 * 5 * 5 =314.159
       

Input  : Radius Of Sphere = 12
Output : Volume    Of    Sphere :  7238.229473870883
         Surface Area Of Sphere :  1809.5573684677208
C++
// CPP program to calculate Volume and
// Surface area of Sphere
#include
using namespace std;
 
// Initializing Value Of PI
float pi = 3.14159;
 
// Function To Calculate Volume Of Sphere
float volume(float r)
{
    float vol;
    vol = (float(4) / float(3)) * pi * r * r * r;
    return vol;
 
}
 
// Function To Calculate Surface Area of Sphere
float surface_area(float r)
{
    float sur_ar;
    sur_ar = 4 * pi * r * r;
    return sur_ar;
}
 
// Driver Function
int main()
{
    float radius = 12;
    float vol, sur_area;
     
    // Function Call
    vol = volume(radius);
    sur_area = surface_area(radius);
 
    // Printing Value Of Volume And Surface Area
    cout << "Volume Of Sphere :" << vol << endl;
    cout << "Surface Area Of Sphere :" << sur_area << endl;
    return 0;
}


Java
// Java program to calculate Volume and
// Surface area of Sphere
class GFG {
     
// Initializing Value Of PI
static float pi = 3.14159f;
 
// Function To Calculate Volume Of Sphere
static float volume(float r)
{
    float vol;
    vol = ((float)4 / (float)3) * (pi * r * r * r);
    return vol;
}
 
// Function To Calculate Surface Area of Sphere
static float surface_area(float r) {
    float sur_ar;
    sur_ar = 4 * pi * r * r;
    return sur_ar;
}
 
// Driver Function
public static void main(String[] args)
{
    float radius = 12;
    float vol, sur_area;
 
    // Function Call
    vol = volume(radius);
    sur_area = surface_area(radius);
     
    // Printing Value Of Volume And Surface Area
    System.out.println("Volume Of Sphere :" + vol);
    System.out.println("Surface Area Of Sphere :" + sur_area);
}
}
 
// This code is contributed by Anant Agarwal.


Python3
''' Python3 program to calculate Volume and
Surface area of Sphere'''
# Importing Math library for value Of PI
import math
pi = math.pi
 
# Function to calculate Volume of Sphere
def volume(r):
    vol = (4 / 3) * pi * r * r * r
    return vol
 
# Function To Calculate Surface Area of Sphere
def surfacearea(r):
    sur_ar = 4 * pi * r * r
    return sur_ar
 
# Driver Code
radius = float(12)
print( "Volume Of Sphere : ", volume(radius) )
print( "Surface Area Of Sphere : ", surfacearea(radius) )


C#
// C# program to calculate Volume and
// Surface area of Sphere
using System;
 
class GFG {
     
    // Initializing Value Of PI
    static float pi = 3.14159f;
     
    // Function To Calculate Volume
    // Of Sphere
    static float volume(float r)
    {
        float vol;
        vol = ((float)4 / (float)3) *
                           (pi * r * r * r);
        return vol;
    }
     
    // Function To Calculate Surface Area
    // of Sphere
    static float surface_area(float r) {
        float sur_ar;
        sur_ar = 4 * pi * r * r;
        return sur_ar;
    }
     
    // Driver Function
    public static void Main()
    {
        float radius = 12;
        float vol, sur_area;
     
        // Function Call
        vol = volume(radius);
        sur_area = surface_area(radius);
         
        // Printing Value Of Volume And
        // Surface Area
        Console.WriteLine("Volume Of Sphere :"
                                        + vol);
        Console.WriteLine("Surface Area Of "
                      + "Sphere :" + sur_area);
    }
}
 
// This code is contributed by vt_m.


PHP


Javascript


输出 :

Volume Of Sphere :7238.22
Surface Area Of Sphere :1809.56