Posted on by Kalkicode
Code Geometric

Find surface area of hemisphere

A hemisphere is a three-dimensional geometric shape that represents half of a sphere, with a flat circular base and a curved surface extending from the base. Finding the surface area of a hemisphere is important in various fields, including physics, engineering, and architecture, where hemispherical structures or objects are encountered.

Problem Statement

Given the radius (r) of the hemisphere, the task is to calculate its surface area. The formula for finding the surface area of a hemisphere in terms of its radius 'r' is:

Surface Area = 2 * π * r²

Example Scenario

Imagine you are designing a hemispherical dome for a planetarium. To plan the materials needed for the curved surface, you need to calculate the surface area of the hemisphere. This calculation helps you estimate the amount of material required to cover the dome accurately.

Idea to Solve the Problem

To solve this problem, you can follow these steps:

  1. Accept the radius 'r' of the hemisphere as an input.
  2. Use the formula to calculate the surface area of the hemisphere.
  3. Display the calculated surface area.

Pseudocode

function hemisphere_surface_area(r):
    area = 2 * π * (r * r)
    return area

main:
    r1 = 14
    r2 = 5
    r3 = 8.2
    
    area1 = hemisphere_surface_area(r1)
    area2 = hemisphere_surface_area(r2)
    area3 = hemisphere_surface_area(r3)
    
    print("Hemisphere [ Radius :", r1, "]")
    print("Surface Area :", area1)
    
    print("Hemisphere [ Radius :", r2, "]")
    print("Surface Area :", area2)
    
    print("Hemisphere [ Radius :", r3, "]")
    print("Surface Area :", area3)

Algorithm Explanation

  1. Define a function hemisphere_surface_area that takes the radius 'r' as an input.
  2. Inside the function, use the provided formula to calculate the surface area of the hemisphere.
  3. In the main function, set three test cases with different radii 'r'.
  4. Calculate the surface areas for each test case by calling the hemisphere_surface_area function.
  5. Display the calculated surface areas along with their respective radius values.

Code Solution

/*
  C Program 
  Find surface area of hemisphere
*/
#include <stdio.h>

#include <math.h>

//Calculate surface area of hemisphere by radius
void hemisphere_surface_area(double r)
{
	// Formula of hemisphere surface area
	// 2πr²
	printf("\nGiven radius : %lf", r);
	//Calculate surface of hemisphere
	double area = 2 * M_PI * (r * r);
	printf("\nSurface area of hemisphere : %lf\n", area);
}
int main()
{
	//Simple Case
	hemisphere_surface_area(14);
	hemisphere_surface_area(5);
	hemisphere_surface_area(8.2);
	return 0;
}

Output

Given radius : 14.000000
Surface area of hemisphere : 1231.504320

Given radius : 5.000000
Surface area of hemisphere : 157.079633

Given radius : 8.200000
Surface area of hemisphere : 422.481380
// Java Program
// Find surface area of Hemisphere
class Hemisphere
{
	//Calculate surface area of hemisphere by radius
	public void surface_area(double r)
	{
		// Formula of hemisphere surface area
		// 2πr²
		System.out.print("\nGiven radius : " + r);
		//Calculate surface of hemisphere
		double area = 2 * Math.PI * (r * r);
		System.out.print("\nSurface area of hemisphere : " + area + "\n");
	}
	public static void main(String[] args)
	{
		Hemisphere obj = new Hemisphere();
		//Simple Case
		obj.surface_area(14);
		obj.surface_area(5);
		obj.surface_area(8.2);
	}
}

Output

Given radius : 14.0
Surface area of hemisphere : 1231.5043202071988

Given radius : 5.0
Surface area of hemisphere : 157.07963267948966

Given radius : 8.2
Surface area of hemisphere : 422.48138005475533
// C++ Program
// Find surface area of Hemisphere
#include<iostream>
#include<math.h>
using namespace std;
class Hemisphere
{
	public:
		//Calculate surface area of hemisphere by radius
		void surface_area(double r)
		{
			cout << "\nGiven radius : " << r;
			// Formula of hemisphere surface area
			// 2πr²
			//Calculate surface of hemisphere
			double area = 2 * M_PI * (r * r);
			cout << "\nSurface area of hemisphere : " << area << "\n";
		}
};
int main()
{
	Hemisphere obj ;
	//Simple Case
	obj.surface_area(14);
	obj.surface_area(5);
	obj.surface_area(8.2);
	return 0;
}

Output

Given radius : 14
Surface area of hemisphere : 1231.5

Given radius : 5
Surface area of hemisphere : 157.08

Given radius : 8.2
Surface area of hemisphere : 422.481
// C# Program
// Find surface area of Hemisphere
using System;
class Hemisphere
{
	//Calculate surface area of hemisphere by radius
	public void surface_area(double r)
	{
		Console.Write("\nGiven radius : " + r);
		// Formula of hemisphere surface area
		// 2πr²
		//Calculate surface of hemisphere
		double area = 2 * Math.PI * (r * r);
		Console.Write("\nSurface area of hemisphere : " + area + "\n");
	}
	public static void Main(String[] args)
	{
		Hemisphere obj = new Hemisphere();
		//Simple Case
		obj.surface_area(14);
		obj.surface_area(5);
		obj.surface_area(8.2);
	}
}

Output

Given radius : 14
Surface area of hemisphere : 1231.5043202072

Given radius : 5
Surface area of hemisphere : 157.07963267949

Given radius : 8.2
Surface area of hemisphere : 422.481380054755
<?php
// Php Program
// Find surface area of Hemisphere
class Hemisphere
{
	//Calculate surface area of hemisphere by radius
	public	function surface_area($r)
	{
		echo "\nGiven radius : ". $r;
		// Formula of hemisphere surface area
		// 2πr²
		//Calculate surface of hemisphere
		$area = 2 * M_PI * ($r * $r);
		echo "\nSurface area of hemisphere : ". $area ."\n";
	}
}

function main()
{
	$obj = new Hemisphere();
	//Simple Case
	$obj->surface_area(14);
	$obj->surface_area(5);
	$obj->surface_area(8.2);
}
main();

Output

Given radius : 14
Surface area of hemisphere : 1231.5043202072

Given radius : 5
Surface area of hemisphere : 157.07963267949

Given radius : 8.2
Surface area of hemisphere : 422.48138005476
// Node Js Program
// Find surface area of Hemisphere
class Hemisphere
{
	//Calculate surface area of hemisphere by radius
	surface_area(r)
	{
		process.stdout.write("\nGiven radius : " + r);
		// Formula of hemisphere surface area
		// 2πr²
		//Calculate surface of hemisphere
		var area = 2 * Math.PI * (r * r);
		process.stdout.write("\nSurface area of hemisphere : " + area + "\n");
	}
}

function main()
{
	var obj = new Hemisphere();
	//Simple Case
	obj.surface_area(14);
	obj.surface_area(5);
	obj.surface_area(8.2);
}
main();

Output

Given radius : 14
Surface area of hemisphere : 1231.5043202071988

Given radius : 5
Surface area of hemisphere : 157.07963267948966

Given radius : 8.2
Surface area of hemisphere : 422.48138005475533
#  Python 3 Program
#  Find surface area of Hemisphere
import math
class Hemisphere :
	# Calculate surface area of hemisphere by radius
	def surface_area(self, r) :
		print("\nGiven radius : ", r, end = "")
		#  Formula of hemisphere surface area
		#  2πr²
		# Calculate surface of hemisphere
		area = 2 * math.pi * (r * r)
		print("\nSurface area of hemisphere : ", area ,"\n", end = "")
	

def main() :
	obj = Hemisphere()
	# Simple Case
	obj.surface_area(14)
	obj.surface_area(5)
	obj.surface_area(8.2)

if __name__ == "__main__": main()

Output

Given radius :  14
Surface area of hemisphere :  1231.5043202071988

Given radius :  5
Surface area of hemisphere :  157.07963267948966

Given radius :  8.2
Surface area of hemisphere :  422.48138005475533
#  Ruby Program
#  Find surface area of Hemisphere
class Hemisphere

	# Calculate surface area of hemisphere by radius
	def surface_area(r)
	
		print("\nGiven radius : ", r)
		#  Formula of hemisphere surface area
		#  2πr²
		# Calculate surface of hemisphere
		area = 2 * Math::PI * (r * r)
		print("\nSurface area of hemisphere : ", area ,"\n")
	end
end
def main()

	obj = Hemisphere.new()
	# Simple Case
	obj.surface_area(14)
	obj.surface_area(5)
	obj.surface_area(8.2)
end
main()

Output

Given radius : 14
Surface area of hemisphere : 1231.5043202071988

Given radius : 5
Surface area of hemisphere : 157.07963267948966

Given radius : 8.2
Surface area of hemisphere : 422.48138005475533
// Scala Program
// Find surface area of Hemisphere
class Hemisphere
{
	//Calculate surface area of hemisphere by radius
	def surface_area(r: Double): Unit = {
		print("\nGiven radius : " + r);
		// Formula of hemisphere surface area
		// 2πr²
		//Calculate surface of hemisphere
		var area: Double = 2 * Math.PI * (r * r);
		print("\nSurface area of hemisphere : " + area + "\n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: Hemisphere = new Hemisphere();
		//Simple Case
		obj.surface_area(14);
		obj.surface_area(5);
		obj.surface_area(8.2);
	}
}

Output

Given radius : 14.0
Surface area of hemisphere : 1231.5043202071988

Given radius : 5.0
Surface area of hemisphere : 157.07963267948966

Given radius : 8.2
Surface area of hemisphere : 422.48138005475533
// Swift Program
// Find surface area of Hemisphere
import Foundation
class Hemisphere
{
	//Calculate surface area of hemisphere by radius
	func surface_area(_ r: Double)
	{
		print("\nGiven radius : ", r, terminator: "");
		// Formula of hemisphere surface area
		// 2πr²
		//Calculate surface of hemisphere
		let area: Double = 2 * Double.pi * (r * r);
		print("\nSurface area of hemisphere : ", area ,"\n", terminator: "");
	}
}
func main()
{
	let obj: Hemisphere = Hemisphere();
	//Simple Case
	obj.surface_area(14);
	obj.surface_area(5);
	obj.surface_area(8.2);
}
main();

Output

Given radius :  14.0
Surface area of hemisphere :  1231.5043202072

Given radius :  5.0
Surface area of hemisphere :  157.07963267949

Given radius :  8.2
Surface area of hemisphere :  422.481380054755

Output Explanation

The code calculates the surface area for each test case and displays the results. For a hemisphere with a radius 'r' = 14, the surface area is approximately 1231.504320. Similarly, for radii 'r' = 5 and 'r' = 8.2, the surface areas are approximately 157.079633 and 422.481380, respectively.

Time Complexity

The time complexity of this code is constant O(1) because the calculations involve basic arithmetic operations (multiplication) and the use of the mathematical constant π (pi). These operations are computed in constant time regardless of the input size. The program performs a fixed number of operations for each test case, making it efficient.

Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment