Calculate volume and surface area of a hemisphere.
Hemisphere :
In geometry, it is an exact half of a sphere. We can find many of the real life examples of the hemispheres such as our planet Earth can be divided into two hemisphere the southern & northern hemispheres.

Volume of Hemisphere : Volume of a Hemisphere is nothing but the amount of space occupied by the hemisphere. It is also defined as the quantity of three dimensional space enclosed by the boundary of the Hemisphere.
Surface area : The number of square units that will exactly cover the surface of a hemisphere.
surface area = 
volume = 
Examples :
Input : Radius = 7
Output :
Volume = 718.378
Surface Area = 307.876
Input : Radius = 11
Output :
Volume = 2787.64
Surface Area = 760.265
C++
#include <bits/stdc++.h>
using namespace std;
#define pi 3.141592653589793
void volume( float r)
{
float volume = float (2 * pi * pow (r, 3)) / float (3);
cout << "Volume = " << volume << endl;
}
void surface_area( float r)
{
float s_area = 2 * pi * pow (r, 2);
cout << "Surface Area = " << s_area << endl;
}
int main()
{
float r = 11;
volume(r);
surface_area(r);
return 0;
}
|
Java
import java.util.*;
import java.lang.*;
public class GfG{
private static final float pi = ( float ) 3.141592653589793 ;
public static void volume( float r)
{
float volume = ( float )( 2 * pi *( float ) Math.pow(r, 3 ))
/ ( float )( 3 );
System.out.println( "Volume = " + volume);
}
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);
}
public static void main(String argc[]){
float r = 11 ;
volume(r);
surface_area(r);
}
}
|
Python
import math
def volume(r):
volume = 2 * math.pi * math. pow (r, 3 ) / 3
print ( "Volume = " , '%.4f' % volume)
def surface_area(r):
s_area = 2 * math.pi * math. pow (r, 2 )
print ( "Surface Area = " , '%.4f' % s_area)
r = 11
volume(r)
surface_area(r)
|
C#
using System;
public class GfG{
private static float pi = ( float ) 3.141592653589793;
public static void volume( float r)
{
float volume = ( float )(2 * pi *( float ) Math.Pow(r, 3))
/ ( float )(3);
Console.WriteLine( "Volume = " + volume);
}
public static void surface_area( float r)
{
float s_area = ( float )2 * pi * ( float )Math.Pow(r, 2);
Console.WriteLine( "Surface Area = " + s_area);
}
public static void Main()
{
float r = 11;
volume(r);
surface_area(r);
}
}
|
PHP
<?php
function volume( $r )
{
$pi =3.141592653589793;
$volume = (2 * $pi *
pow( $r , 3)) /(3);
echo ( "Volume = " );
echo ( $volume );
echo ( "\n" );
}
function surface_area( $r )
{
$pi = 3.141592653589793;
$s_area = 2 * $pi * pow( $r , 2);
echo ( "Surface Area = " );
echo ( $s_area ) ;
}
$r = 11;
volume( $r );
surface_area( $r );
?>
|
Javascript
<script>
const pi = 3.141592653589793;
function volume(r)
{
let volume = (2 * pi * Math.pow(r, 3)) / (3);
document.write( "Volume = " + volume.toFixed(2)+ "<br/>" );
}
function surface_area(r)
{
let s_area = 2 * pi * Math.pow(r, 2);
document.write( "Surface Area = " + s_area.toFixed(3) + "<br/>" );
}
let r = 11;
volume(r);
surface_area(r);
</script>
|
OutputVolume = 2787.64
Surface Area = 760.265
Time complexity: O(1), as calculating square and cube using pow function takes constant operations.
Auxiliary space: O(1)