Find surface area of hemisphere

Here given code implementation process.

/*
  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


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







© 2021, kalkicode.com, All rights reserved