Find surface area of octahedron

Here given code implementation process.

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

//Calculate surface area of octahedron by side
void surface_area(double side)
{
	// Formula of octahedron surface area
	// 2 √(3) side²
	printf("\nGiven Side : %lf", side);
	//Calculate surface of octahedron
	double area = 2 * sqrt(3) * (side * side);
	printf("\nSurface area of octahedron : %lf\n", area);
}
int main()
{
	//Simple Case
	surface_area(4.8);
	surface_area(5);
	surface_area(6.2);
	return 0;
}

Output

Given Side : 4.800000
Surface area of octahedron : 79.812901

Given Side : 5.000000
Surface area of octahedron : 86.602540

Given Side : 6.200000
Surface area of octahedron : 133.160066
// Java Program
// Find surface area of octahedron
class Octahedron
{
	//Calculate surface area of octahedron by side
	public void surface_area(double side)
	{
		// Formula of octahedron surface area
		// 2 √(3) side²
		System.out.print("\nGiven Side : " + side);
		//Calculate surface of octahedron
		double area = 2 * Math.sqrt(3) * (side * side);
		System.out.print("\nSurface area of octahedron : " + area + "\n");
	}
	public static void main(String[] args)
	{
		Octahedron obj = new Octahedron();
		//Simple Case
		obj.surface_area(4.8);
		obj.surface_area(5);
		obj.surface_area(6.2);
	}
}

Output

Given Side : 4.8
Surface area of octahedron : 79.81290121277385

Given Side : 5.0
Surface area of octahedron : 86.60254037844386

Given Side : 6.2
Surface area of octahedron : 133.1600660858953
// C++ Program
// Find surface area of octahedron
#include<iostream>
#include<math.h>
using namespace std;
class Octahedron
{
	public:
		//Calculate surface area of octahedron by side
		void surface_area(double side)
		{	
          
			// Formula of octahedron surface area
			// 2 √(3) side²
			cout << "\nGiven Side : " << side;
			//Calculate surface of octahedron
			double area = 2 * sqrt(3) * (side * side);
			cout << "\nSurface area of octahedron : " << area << "\n";
		}
};
int main()
{
	Octahedron obj;
	//Simple Case
	obj.surface_area(4.8);
	obj.surface_area(5);
	obj.surface_area(6.2);
	return 0;
}

Output

Given Side : 4.8
Surface area of octahedron : 79.8129

Given Side : 5
Surface area of octahedron : 86.6025

Given Side : 6.2
Surface area of octahedron : 133.16
// C# Program
// Find surface area of octahedron
using System;
class Octahedron
{
	//Calculate surface area of octahedron by side
	public void surface_area(double side)
	{
		Console.Write("\nGiven Side : " + side);
		// Formula of octahedron surface area
		// 2 √(3) side²
		//Calculate surface of octahedron
		double area = 2 * Math.Sqrt(3) * (side * side);
		Console.Write("\nSurface area of octahedron : " + area + "\n");
	}
	public static void Main(String[] args)
	{
		Octahedron obj = new Octahedron();
		//Simple Case
		obj.surface_area(4.8);
		obj.surface_area(5);
		obj.surface_area(6.2);
	}
}

Output

Given Side : 4.8
Surface area of octahedron : 79.8129012127739

Given Side : 5
Surface area of octahedron : 86.6025403784439

Given Side : 6.2
Surface area of octahedron : 133.160066085895
<?php
// Php Program
// Find surface area of octahedron
class Octahedron
{
	//Calculate surface area of octahedron by side
	public	function surface_area($side)
	{
		echo "\nGiven Side : ". $side;
		// Formula of octahedron surface area
		// 2 √(3) side²
		//Calculate surface of octahedron
		$area = 2 * sqrt(3) * ($side * $side);
		echo "\nSurface area of octahedron : ". $area ."\n";
	}
}

function main()
{
	$obj = new Octahedron();
	//Simple Case
	$obj->surface_area(4.8);
	$obj->surface_area(5);
	$obj->surface_area(6.2);
}
main();

Output

Given Side : 4.8
Surface area of octahedron : 79.812901212774

Given Side : 5
Surface area of octahedron : 86.602540378444

Given Side : 6.2
Surface area of octahedron : 133.1600660859
// Node Js Program
// Find surface area of octahedron
class Octahedron
{
	//Calculate surface area of octahedron by side
	surface_area(side)
	{
		process.stdout.write("\nGiven Side : " + side);
		// Formula of octahedron surface area
		// 2 √(3) side²
		//Calculate surface of octahedron
		var area = 2 * Math.sqrt(3) * (side * side);
		process.stdout.write("\nSurface area of octahedron : " + area + "\n");
	}
}

function main()
{
	var obj = new Octahedron();
	//Simple Case
	obj.surface_area(4.8);
	obj.surface_area(5);
	obj.surface_area(6.2);
}
main();

Output

Given Side : 4.8
Surface area of octahedron : 79.81290121277385

Given Side : 5
Surface area of octahedron : 86.60254037844386

Given Side : 6.2
Surface area of octahedron : 133.1600660858953
#  Python 3 Program
#  Find surface area of octahedron

import math

class Octahedron :
	# Calculate surface area of octahedron by side
	def surface_area(self, side) :
		print("\nGiven Side : ", side, end = "")
		#  Formula of octahedron surface area
		#  2 √(3) side²
		# Calculate surface of octahedron
		area = 2 * math.sqrt(3) * (side * side)
		print("\nSurface area of octahedron : ", area ,"\n", end = "")
	

def main() :
	obj = Octahedron()
	# Simple Case
	obj.surface_area(4.8)
	obj.surface_area(5)
	obj.surface_area(6.2)

if __name__ == "__main__": main()

Output

Given Side :  4.8
Surface area of octahedron :  79.81290121277385

Given Side :  5
Surface area of octahedron :  86.60254037844386

Given Side :  6.2
Surface area of octahedron :  133.1600660858953
#  Ruby Program
#  Find surface area of octahedron
class Octahedron

	# Calculate surface area of octahedron by side
	def surface_area(side)
	
		print("\nGiven Side : ", side)
		#  Formula of octahedron surface area
		#  2 √(3) side²
		# Calculate surface of octahedron
		area = 2 * Math.sqrt(3) * (side * side)
		print("\nSurface area of octahedron : ", area ,"\n")
	end
end
def main()

	obj = Octahedron.new()
	# Simple Case
	obj.surface_area(4.8)
	obj.surface_area(5)
	obj.surface_area(6.2)
end
main()

Output

Given Side : 4.8
Surface area of octahedron : 79.81290121277385

Given Side : 5
Surface area of octahedron : 86.60254037844386

Given Side : 6.2
Surface area of octahedron : 133.1600660858953
// Scala Program
// Find surface area of octahedron
class Octahedron
{
	//Calculate surface area of octahedron by side
	def surface_area(side: Double): Unit = {
		print("\nGiven Side : " + side);
		// Formula of octahedron surface area
		// 2 √(3) side²
		//Calculate surface of octahedron
		var area: Double = 2 * Math.sqrt(3) * (side * side);
		print("\nSurface area of octahedron : " + area + "\n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: Octahedron = new Octahedron();
		//Simple Case
		obj.surface_area(4.8);
		obj.surface_area(5);
		obj.surface_area(6.2);
	}
}

Output

Given Side : 4.8
Surface area of octahedron : 79.81290121277385

Given Side : 5.0
Surface area of octahedron : 86.60254037844386

Given Side : 6.2
Surface area of octahedron : 133.1600660858953
// Swift Program
// Find surface area of octahedron
import Foundation
class Octahedron
{
	//Calculate surface area of octahedron by side
	func surface_area(_ side: Double)
	{
		print("\nGiven Side : ", side, terminator: "");
		// Formula of octahedron surface area
		// 2 √(3) side²
		//Calculate surface of octahedron
		let area: Double = 2 * sqrt(3) * (side * side);
		print("\nSurface area of octahedron : ", area ,"\n", terminator: "");
	}
}
func main()
{
	let obj: Octahedron = Octahedron();
	//Simple Case
	obj.surface_area(4.8);
	obj.surface_area(5);
	obj.surface_area(6.2);
}
main();

Output

Given Side :  4.8
Surface area of octahedron :  79.8129012127739

Given Side :  5.0
Surface area of octahedron :  86.6025403784439

Given Side :  6.2
Surface area of octahedron :  133.160066085895


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