Calculate volume and surface area of a cone
Last Updated :
29 Feb, 2024
Given slant height, height and radius of a cone, we have to calculate the volume and surface area of the cone.
Â
- Cone :Â
Cone is a three dimensional geometric shape. It consists of a base having the shape of a circle and a curved side (the lateral surface) ending up in a tip called the apex or vertex.Â
Â
Â
- Volume of a cone :Â
The volume of a cone is given by the formula –Â
Â
volume = 1/3(pi * r * r * h)
- where r is the radius of the circular base, and h is the height (the perpendicular distance from the base to the vertex).
Â
area = pi * r * s + pi * r^2
- Where r is the radius of the circular base, and s is the slant height of the cone.
Examples :Â
Â
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++
#include<iostream>
using namespace std;
float pi = 3.14159;
float volume( float r, float h)
{
return ( float (1) / float (3)) * pi *
r * r * h;
}
float surface_area( float r, float s)
{
return pi * r * s + pi * r * r;
}
int main()
{
float radius = 5;
float slant_height = 13;
float height = 12;
float vol, sur_area;
cout << "Volume Of Cone : "
<< volume(radius, height) << endl;
cout << "Surface Area Of Cone : "
<< surface_area(radius, slant_height);
return 0;
}
|
Java
class GFG
{
static float pi = 3 .14159f;
public static float volume( float r,
float h)
{
return ( float ) 1 / 3 * pi * h *
r * r;
}
public static float surface_area( float r,
float s)
{
return pi * r * s + pi * r * r;
}
public static void main(String args[])
{
float radius = 5 ;
float slant_height = 13 ;
float height = 12 ;
float vol, sur_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));
}
}
|
Python
import math
pi = math.pi
def volume(r, h):
return ( 1 / 3 ) * pi * r * r * h
def surfacearea(r, s):
return pi * r * s + pi * r * r
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#
using System;
class GFG
{
static float pi = 3.14159f;
public static float volume( float r,
float h)
{
return ( float )1 / 3 * pi * h *
r * r;
}
public static float surface_area( float r,
float s)
{
return pi * r * s + pi * r * r;
}
public static void Main()
{
float radius = 5;
float slant_height = 13;
float height = 12;
Console.Write( "Volume Of Cone : " );
Console.WriteLine(volume(radius,
height));
Console.Write( "Surface Area Of Cone : " );
Console.WriteLine(surface_area(radius,
slant_height));
}
}
|
Javascript
<script>
const pi = 3.14159;
function volume( r, h)
{
return ((1) / (3)) * pi *
r * r * h;
}
function surface_area( r, s)
{
return pi * r * s + pi * r * r;
}
let radius = 5;
let slant_height = 13;
let height = 12;
let vol, sur_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/>" );
</script>
|
PHP
<?php
function volume( $r , $h )
{
$pi = 3.14159;
return (1 / 3) * $pi * $r *
$r * $h ;
}
function surface_area( $r , $s )
{
$pi = 3.14159;
return $pi * $r * $s + $pi *
$r * $r ;
}
$radius = 5;
$slant_height = 13;
$height = 12;
echo ( "Volume Of Cone : " );
echo ( volume( $radius , $height ));
echo ( "\n" );
echo ( "Surface Area Of Cone : " );
echo ( surface_area( $radius ,
$slant_height ));
?>
|
Output :Â
Â
Volume Of Cone : 314.159
Surface Area Of Cone : 282.743
Time complexity : O(1)Â
Auxiliary Space : O(1)Â
Share your thoughts in the comments
Please Login to comment...