Find the area of a Hexagon

Here given code implementation process.

/*
  C Program 
  Find the area of a Hexagon 
*/
#include <stdio.h>

#include <math.h>

//Calculate area of hexagon by given side length
void hexagon_area(double side)
{
	// Formula of hexagon area
	// (3 √3(side)² ) / 2
	// Calculate area of hexagon
	double area = (3 * sqrt(3) * (side * side)) / 2;
	//Display result
	printf("Hexagon Area of side %lf is : %lf\n", side, area);
}
int main()
{
	//Test Case
	hexagon_area(7);
	hexagon_area(3);
	hexagon_area(5.2);
	return 0;
}

Output

Hexagon Area of side 7.000000 is : 127.305734
Hexagon Area of side 3.000000 is : 23.382686
Hexagon Area of side 5.200000 is : 70.251981
// Java Program
// Find the area of a Hexagon 
class Hexagon
{
	//Calculate area of hexagon by given side length
	public void hexagon_area(double side)
	{
		// Formula of hexagon area
		// (3 √3(side)² ) / 2
		// Calculate area of hexagon
		double area = (3 * Math.sqrt(3) * (side * side)) / 2;
		System.out.print("Hexagon Area of side " + side + " is : " + area + "\n");
	}
	public static void main(String[] args)
	{
		Hexagon obj = new Hexagon();
		//Simple Case
		obj.hexagon_area(7);
		obj.hexagon_area(3);
		obj.hexagon_area(5.2);
	}
}

Output

Hexagon Area of side 7.0 is : 127.30573435631248
Hexagon Area of side 3.0 is : 23.382685902179844
Hexagon Area of side 5.2 is : 70.25198075499367
// C++ Program
// Find the area of a Hexagon 
#include<iostream>
#include<math.h>
using namespace std;
class Hexagon
{
	public:
		//Calculate area of hexagon by given side length
		void hexagon_area(double side)
		{
			// Formula of hexagon area
			// (3 √3(side)² ) / 2
			// Calculate area of hexagon
			double area = (3 * sqrt(3) * (side * side)) / 2;
			cout << "Hexagon Area of side " << side << " is : " << area << "\n";
		}
};
int main()
{
	Hexagon obj =  Hexagon();
	//Simple Case
	obj.hexagon_area(7);
	obj.hexagon_area(3);
	obj.hexagon_area(5.2);
	return 0;
}

Output

Hexagon Area of side 7 is : 127.306
Hexagon Area of side 3 is : 23.3827
Hexagon Area of side 5.2 is : 70.252
// C# Program
// Find the area of a Hexagon 
using System;
class Hexagon
{
	//Calculate area of hexagon by given side length
	public void hexagon_area(double side)
	{
		// Formula of hexagon area
		// (3 √3(side)² ) / 2
		// Calculate area of hexagon
		double area = (3 * Math.Sqrt(3) * (side * side)) / 2;
		Console.Write("Hexagon Area of side " + side + " is : " + area + "\n");
	}
	public static void Main(String[] args)
	{
		Hexagon obj = new Hexagon();
		//Simple Case
		obj.hexagon_area(7);
		obj.hexagon_area(3);
		obj.hexagon_area(5.2);
	}
}

Output

Hexagon Area of side 7 is : 127.305734356312
Hexagon Area of side 3 is : 23.3826859021798
Hexagon Area of side 5.2 is : 70.2519807549937
<?php
// Php Program
// Find the area of a Hexagon 
class Hexagon
{
	//Calculate area of hexagon by given side length
	public	function hexagon_area($side)
	{
		// Formula of hexagon area
		// (3 √3(side)² ) / 2
		// Calculate area of hexagon
		$area = (3 * sqrt(3) * ($side * $side)) / 2;
		echo "Hexagon Area of side ". $side ." is : ". $area ."\n";
	}
}

function main()
{
	$obj = new Hexagon();
	//Simple Case
	$obj->hexagon_area(7);
	$obj->hexagon_area(3);
	$obj->hexagon_area(5.2);
}
main();

Output

Hexagon Area of side 7 is : 127.30573435631
Hexagon Area of side 3 is : 23.38268590218
Hexagon Area of side 5.2 is : 70.251980754994
// Node Js Program
// Find the area of a Hexagon 
class Hexagon
{
	//Calculate area of hexagon by given side length
	hexagon_area(side)
	{
		// Formula of hexagon area
		// (3 √3(side)² ) / 2
		// Calculate area of hexagon
		var area = (3 * Math.sqrt(3) * (side * side)) / 2;
		process.stdout.write("Hexagon Area of side " + side + " is : " + area + "\n");
	}
}

function main()
{
	var obj = new Hexagon();
	//Simple Case
	obj.hexagon_area(7);
	obj.hexagon_area(3);
	obj.hexagon_area(5.2);
}
main();

Output

Hexagon Area of side 7 is : 127.30573435631248
Hexagon Area of side 3 is : 23.382685902179844
Hexagon Area of side 5.2 is : 70.25198075499367
#  Python 3 Program
#  Find the area of a Hexagon 

import math

class Hexagon :
	# Calculate area of hexagon by given side length
	def hexagon_area(self, side) :
		#  Formula of hexagon area
		#  (3 √3(side)² ) / 2
		#  Calculate area of hexagon
		area = (3 * math.sqrt(3) * (side * side)) / 2
		print("Hexagon Area of side ", side ," is : ", area ,"\n", end = "")
	

def main() :
	obj = Hexagon()
	# Simple Case
	obj.hexagon_area(7)
	obj.hexagon_area(3)
	obj.hexagon_area(5.2)

if __name__ == "__main__": main()

Output

Hexagon Area of side  7  is :  127.30573435631248
Hexagon Area of side  3  is :  23.382685902179844
Hexagon Area of side  5.2  is :  70.25198075499367
#  Ruby Program
#  Find the area of a Hexagon 
class Hexagon

	# Calculate area of hexagon by given side length
	def hexagon_area(side)
	
		#  Formula of hexagon area
		#  (3 √3(side)² ) / 2
		#  Calculate area of hexagon
		area = (3 * Math.sqrt(3) * (side * side)) / 2
		print("Hexagon Area of side ", side ," is : ", area ,"\n")
	end
end
def main()

	obj = Hexagon.new()
	# Simple Case
	obj.hexagon_area(7)
	obj.hexagon_area(3)
	obj.hexagon_area(5.2)
end
main()

Output

Hexagon Area of side 7 is : 127.30573435631248
Hexagon Area of side 3 is : 23.382685902179844
Hexagon Area of side 5.2 is : 70.25198075499367
// Scala Program
// Find the area of a Hexagon 
class Hexagon
{
	//Calculate area of hexagon by given side length
	def hexagon_area(side: Double): Unit = {
		// Formula of hexagon area
		// (3 √3(side)² ) / 2
		// Calculate area of hexagon
		var area: Double = (3 * Math.sqrt(3) * (side * side)) / 2;
		print("Hexagon Area of side " + side + " is : " + area + "\n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: Hexagon = new Hexagon();
		//Simple Case
		obj.hexagon_area(7);
		obj.hexagon_area(3);
		obj.hexagon_area(5.2);
	}
}

Output

Hexagon Area of side 7.0 is : 127.30573435631248
Hexagon Area of side 3.0 is : 23.382685902179844
Hexagon Area of side 5.2 is : 70.25198075499367
// Swift Program
// Find the area of a Hexagon 
import Foundation
class Hexagon
{
	//Calculate area of hexagon by given side length
	func hexagon_area(_ side: Double)
	{
		// Formula of hexagon area
		// (3 √3(side)² ) / 2
		// Calculate area of hexagon
		let area: Double = (3 * sqrt(3) * (side * side)) / 2;
		print("Hexagon Area of side ", side ," is : ", area ,"\n", terminator: "");
	}
}
func main()
{
	let obj: Hexagon = Hexagon();
	//Simple Case
	obj.hexagon_area(7);
	obj.hexagon_area(3);
	obj.hexagon_area(5.2);
}
main();

Output

Hexagon Area of side  7.0  is :  127.305734356312
Hexagon Area of side  3.0  is :  23.3826859021798
Hexagon Area of side  5.2  is :  70.2519807549937


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