Calcular el volumen y la superficie de un cono

Dada la altura inclinada, la altura y el radio de un cono, tenemos que calcular el volumen y el área de superficie del cono.
 

  • Cono: 
    El cono es una forma geométrica tridimensional. Consiste en una base que tiene forma de círculo y un lado curvo (la superficie lateral) que termina en una punta llamada ápice o vértice. 
     

Calculate volume of a cone

  • Volumen de un cono: 
    El volumen de un cono viene dado por la fórmula: 
     
volume = 1/3(pi * r * r * h)
  • donde r es el radio de la base circular y h es la altura (la distancia perpendicular desde la base hasta el vértice).
  • Área de superficie de un cono: 
    El área de superficie de un cono viene dada por la fórmula: 
     
area = pi * r * s + pi * r^2  
  • Donde r es el radio de la base circular y s es la altura inclinada del cono.

Ejemplos: 
 

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<iostream>
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

<?php
// PHP program to calculate Volume
// and Surface area of Cone
 
// Function to calculate Volume of cone
function volume( $r, $h)
{
    $pi = 3.14159;
    return (1 / 3) * $pi * $r *
                     $r * $h;
}
 
// Function to calculate
// Surface area of cone
function surface_area($r, $s)
{
    $pi = 3.14159;
    return $pi * $r * $s + $pi *
                      $r * $r;
}
 
// Driver Code
 
    $radius = 5;
    $slant_height = 13;
    $height = 12;
    //vol, sur_area;
 
    // Printing value of volume
    // and surface area
    echo("Volume Of Cone : ");
    echo( volume($radius, $height));
    echo("\n");
    echo("Surface Area Of Cone : ");
    echo( surface_area($radius,
                       $slant_height));
     
// This code is contributed by vt_m.
     
?>

Javascript

<script>
// javascript program to calculate Volume
// and Surface area of Cone
 
const pi = 3.14159;
 
// Function to calculate
// Volume of cone
function volume( r,  h)
{
    return ((1) / (3)) * pi *
                             r * r * h;
}
 
// Function to calculate
// Surface area of cone
function surface_area( r,  s)
{
    return pi * r * s + pi * r * r;
}
 
// Driver Code
 
    let radius = 5;
    let slant_height = 13;
    let height = 12;
    let vol, sur_area;
 
    // Printing value of volume
    // and surface area
   document.write( "Volume Of Cone : "
        + volume(radius, height).toFixed(2) +"<br/>");
    document.write( "Surface Area Of Cone : "
        + surface_area(radius, slant_height).toFixed(2) +"<br/>");
 
// This code is contributed by Rajput-Ji
 
</script>

Producción : 
 

Volume Of Cone : 314.159
Surface Area Of Cone : 282.743

Complejidad temporal : O(1) 
Espacio auxiliar : O(1) 

Publicación traducida automáticamente

Artículo escrito por rishabh_jain y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *