📜  计算圆锥的体积和表面积

📅  最后修改于: 2021-04-27 23:04:38             🧑  作者: Mango

给定圆锥体的倾斜高度,高度和半径,我们必须计算圆锥体的体积和表面积。

  • 锥体:
    圆锥是三维几何形状。它由一个圆形的基部和一个弯曲的侧面(侧面)组成,该侧面终止于称为顶点或顶点的尖端。

  • 锥体体积:
    圆锥体的体积由以下公式给出:
volume = 1/3(pi * r * r * h)
  • 其中, r是圆底的半径, h是高度(从底到顶点的垂直距离)。
  • 圆锥体的表面积:
    圆锥体的表面积由以下公式给出:
area = pi * r * s + pi * r^2  
  • 其中r是圆底的半径, s是圆锥的倾斜高度。

例子 :

Input : 
radius = 5
slant_height = 13
height = 12
Output :
Volume Of Cone = 314.159
Surface Area Of Cone = 282.743

Input :
radius = 6
slant_height = 10
height = 8
Output : 
Volume Of Cone = 301.593
Surface Area Of Cone = 301.593
C++
// CPP program to calculate Volume
// and Surface area of Cone
#include
using namespace std;
 
float pi = 3.14159;
 
// Function to calculate
// Volume of cone
float volume(float r, float h)
{
    return (float(1) / float(3)) * pi *
                             r * r * h;
}
 
// Function to calculate
// Surface area of cone
float surface_area(float r, float s)
{
    return pi * r * s + pi * r * r;
}
 
// Driver Code
int main()
{
    float radius = 5;
    float slant_height = 13;
    float height = 12;
    float vol, sur_area;
 
    // Printing value of volume
    // and surface area
    cout << "Volume Of Cone : "
        << volume(radius, height) << endl;
    cout << "Surface Area Of Cone : "
        << surface_area(radius, slant_height);
    return 0;
}


Java
// Java program to calculate
// Volume and Surface area of cone
class GFG
{
    static float pi = 3.14159f;
 
    // Function to calculate
    // Volume of cone
    public static float volume(float r,
                               float h)
    {
        return (float)1 / 3 * pi * h *
                               r * r;
    }
 
    // Function to calculate
    // Surface area of cone
    public static float surface_area(float r,
                                     float s)
    {
        return pi * r * s + pi * r * r;
    }
 
    // Driver Code
    public static void main(String args[])
    {
        float radius = 5;
        float slant_height = 13;
        float height = 12;
        float vol, sur_area;
 
        // Printing value of volume
        // and surface area
        System.out.print("Volume Of Cone : ");
        System.out.println(volume(radius, height));
 
        System.out.print("Surface Area Of Cone : ");
        System.out.println(surface_area(radius,
                                        slant_height));
         
    }
}
 
// This code is contributed by "akanshgupta"


Python
''' Python3 program to calculate Volume and
    Surface area of Cone'''
 
# Importing Math library for value Of PI
import math
pi = math.pi
 
# Function to calculate Volume of Cone
def volume(r, h):
    return (1 / 3) * pi * r * r * h
 
# Function To Calculate Surface Area of Cone
def surfacearea(r, s):
    return pi * r * s + pi * r * r
 
# Driver Code
radius = float(5)
height = float(12)
slat_height = float(13)
print( "Volume Of Cone : ", volume(radius, height) )
print( "Surface Area Of Cone : ", surfacearea(radius, slat_height) )


C#
// C# program to calculate
// Volume and Surface area of cone
using System;
 
class GFG
{
    static float pi = 3.14159f;
 
    // Function to calculate
    // Volume of cone
    public static float volume(float r,
                               float h)
    {
        return (float)1 / 3 * pi * h *
                               r * r;
    }
 
    // Function to calculate
    // Surface area of cone
    public static float surface_area(float r,
                                     float s)
    {
        return pi * r * s + pi * r * r;
    }
 
    // Driver Code
    public static void Main()
    {
        float radius = 5;
        float slant_height = 13;
        float height = 12;
        //float vol, sur_area;
 
        // Printing value of volume
        // and surface area
        Console.Write("Volume Of Cone : ");
        Console.WriteLine(volume(radius,
                                 height));
 
        Console.Write("Surface Area Of Cone : ");
        Console.WriteLine(surface_area(radius,
                                       slant_height));
         
    }
}
 
// This code is contributed by "vt_m"


PHP


Javascript


输出 :

Volume Of Cone : 314.159
Surface Area Of Cone : 282.743