Find the area of a Octagon

Here given code implementation process.

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

#include <math.h>

//Calculate area of octagon by given side length
void octagon_area(double side)
{
	// Formula of octagon area
	// ( 2 × (side)² × (1+√2)
	// Calculate area of octagon
	double area = 2 * (side * side) * (1 + sqrt(2));
	//Display result
	printf("Octagon Area of side %lf is : %lf\n", side, area);
}
int main()
{
	//Test Case
	octagon_area(6);
	octagon_area(5);
	octagon_area(5.2);
	return 0;
}

Output

Octagon Area of side 6.000000 is : 173.823376
Octagon Area of side 5.000000 is : 120.710678
Octagon Area of side 5.200000 is : 130.560669
// Java Program
// Find the area of a octagon 
class Octagon
{
	//Calculate area of octagon by given side length
	public void octagon_area(double side)
	{
		// Formula of octagon area
		// ( 2 × (side)² × (1+√2)
		// Calculate area of octagon
		double area = 2 * (side * side) * (1 + Math.sqrt(2));
		System.out.print("Octagon Area of side length " + side + " is : " + area + "\n");
	}
	public static void main(String[] args)
	{
		Octagon obj = new Octagon();
		//Simple Case
		obj.octagon_area(6);
		obj.octagon_area(5);
		obj.octagon_area(5.2);
	}
}

Output

Octagon Area of side length 6.0 is : 173.82337649086284
Octagon Area of side length 5.0 is : 120.71067811865474
Octagon Area of side length 5.2 is : 130.560669453137
// C++ Program
// Find the area of a octagon 
#include<iostream>
#include<math.h>
using namespace std;
class Octagon
{
	public:
		//Calculate area of octagon by given side length
		void octagon_area(double side)
		{
			// Formula of octagon area
			// ( 2 × (side)² × (1+√2)
			// Calculate area of octagon
			double area = 2 * (side * side) * (1 + sqrt(2));
			cout << "Octagon Area of side length " << side << " is : " << area << "\n";
		}
};
int main()
{
	Octagon obj =  Octagon();
	//Simple Case
	obj.octagon_area(6);
	obj.octagon_area(5);
	obj.octagon_area(5.2);
	return 0;
}

Output

Octagon Area of side length 6 is : 173.823
Octagon Area of side length 5 is : 120.711
Octagon Area of side length 5.2 is : 130.561
// C# Program
// Find the area of a octagon 
using System;
class Octagon
{
	//Calculate area of octagon by given side length
	public void octagon_area(double side)
	{
		// Formula of octagon area
		// ( 2 × (side)² × (1+√2)
		// Calculate area of octagon
		double area = 2 * (side * side) * (1 + Math.Sqrt(2));
		Console.Write("Octagon Area of side length " + side + " is : " + area + "\n");
	}
	public static void Main(String[] args)
	{
		Octagon obj = new Octagon();
		//Simple Case
		obj.octagon_area(6);
		obj.octagon_area(5);
		obj.octagon_area(5.2);
	}
}

Output

Octagon Area of side length 6 is : 173.823376490863
Octagon Area of side length 5 is : 120.710678118655
Octagon Area of side length 5.2 is : 130.560669453137
<?php
// Php Program
// Find the area of a octagon 
class Octagon
{
	//Calculate area of octagon by given side length
	public	function octagon_area($side)
	{
		// Formula of octagon area
		// ( 2 × (side)² × (1+√2)
		// Calculate area of octagon
		$area = 2 * ($side * $side) * (1 + sqrt(2));
		echo "Octagon Area of side length ". $side ." is : ". $area ."\n";
	}
}

function main()
{
	$obj = new Octagon();
	//Simple Case
	$obj->octagon_area(6);
	$obj->octagon_area(5);
	$obj->octagon_area(5.2);
}
main();

Output

Octagon Area of side length 6 is : 173.82337649086
Octagon Area of side length 5 is : 120.71067811865
Octagon Area of side length 5.2 is : 130.56066945314
// Node Js Program
// Find the area of a octagon 
class Octagon
{
	//Calculate area of octagon by given side length
	octagon_area(side)
	{
		// Formula of octagon area
		// ( 2 × (side)² × (1+√2)
		// Calculate area of octagon
		var area = 2 * (side * side) * (1 + Math.sqrt(2));
		process.stdout.write("Octagon Area of side length " + side + " is : " + area + "\n");
	}
}

function main()
{
	var obj = new Octagon();
	//Simple Case
	obj.octagon_area(6);
	obj.octagon_area(5);
	obj.octagon_area(5.2);
}
main();

Output

Octagon Area of side length 6 is : 173.82337649086284
Octagon Area of side length 5 is : 120.71067811865474
Octagon Area of side length 5.2 is : 130.560669453137
#  Python 3 Program
#  Find the area of a octagon 

import math

class Octagon :
	# Calculate area of octagon by given side length
	def octagon_area(self, side) :
		#  Formula of octagon area
		#  ( 2 × (side)² × (1+√2)
		#  Calculate area of octagon
		area = 2 * (side * side) * (1 + math.sqrt(2))
		print("Octagon Area of side length ", side ," is : ", area ,"\n", end = "")
	

def main() :
	obj = Octagon()
	# Simple Case
	obj.octagon_area(6)
	obj.octagon_area(5)
	obj.octagon_area(5.2)

if __name__ == "__main__": main()

Output

Octagon Area of side length  6  is :  173.82337649086284
Octagon Area of side length  5  is :  120.71067811865474
Octagon Area of side length  5.2  is :  130.560669453137
#  Ruby Program
#  Find the area of a octagon 
class Octagon

	# Calculate area of octagon by given side length
	def octagon_area(side)
	
		#  Formula of octagon area
		#  ( 2 × (side)² × (1+√2)
		#  Calculate area of octagon
		area = 2 * (side * side) * (1 + Math.sqrt(2))
		print("Octagon Area of side length ", side ," is : ", area ,"\n")
	end
end
def main()

	obj = Octagon.new()
	# Simple Case
	obj.octagon_area(6)
	obj.octagon_area(5)
	obj.octagon_area(5.2)
end
main()

Output

Octagon Area of side length 6 is : 173.82337649086284
Octagon Area of side length 5 is : 120.71067811865474
Octagon Area of side length 5.2 is : 130.560669453137
// Scala Program
// Find the area of a octagon 
class Octagon
{
	//Calculate area of octagon by given side length
	def octagon_area(side: Double): Unit = {
		// Formula of octagon area
		// ( 2 × (side)² × (1+√2)
		// Calculate area of octagon
		var area: Double = 2 * (side * side) * (1 + Math.sqrt(2));
		print("Octagon Area of side length " + side + " is : " + area + "\n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: Octagon = new Octagon();
		//Simple Case
		obj.octagon_area(6);
		obj.octagon_area(5);
		obj.octagon_area(5.2);
	}
}

Output

Octagon Area of side length 6.0 is : 173.82337649086284
Octagon Area of side length 5.0 is : 120.71067811865474
Octagon Area of side length 5.2 is : 130.560669453137
// Swift Program
// Find the area of a octagon 

import Foundation

class Octagon
{
	//Calculate area of octagon by given side length
	func octagon_area(_ side: Double)
	{
		// Formula of octagon area
		// ( 2 × (side)² × (1+√2)
		// Calculate area of octagon
		let area: Double = 2 * (side * side) * (1 + sqrt(2));
		print("Octagon Area of side length ", side ," is : ", area ,"\n", terminator: "");
	}
}
func main()
{
	let obj: Octagon = Octagon();
	//Simple Case
	obj.octagon_area(6);
	obj.octagon_area(5);
	obj.octagon_area(5.2);
}
main();

Output

Octagon Area of side length  6.0  is :  173.823376490863
Octagon Area of side length  5.0  is :  120.710678118655
Octagon Area of side length  5.2  is :  130.560669453137


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