Find volume of Icosahedron

Here given code implementation process.

//C Program
//Find volume of Icosahedron
#include <stdio.h>

#include <math.h>
 //Calculate volume of Icosahedron by given side
void icosahedron_volume(double side)
{
  //Calculate Formula
  //5/12 (3 + √5)(side³)
  double volume = ((double) 5 / 12) * (3 + sqrt(5)) * (side * side * side);
  //Display the result of icosahedron volume
  printf(" Icosahedron  [ Side : %lf ] ", side);
  printf("\n Volume : %lf\n\n", volume);
}
int main()
{
  //Test Cases  
  icosahedron_volume(4);
  icosahedron_volume(8);
  icosahedron_volume(13.6);
  return 0;
}

Output

 Icosahedron  [ Side : 4.000000 ]
 Volume : 139.628479

 Icosahedron  [ Side : 8.000000 ]
 Volume : 1117.027835

 Icosahedron  [ Side : 13.600000 ]
 Volume : 5487.957754
// Java Program
// Find volume of Icosahedron
class IcosahedronVolume
{
  //Calculate volume of Icosahedron by given side
  public void icosahedron_volume(double side)
  {
    //Calculate Formula
    //5/12 (3 + √5)(side³)
    double volume = ((double) 5 / 12) * (3 + Math.sqrt(5)) * (side * side * side);
    //Display the result of icosahedron volume
    System.out.print(" Icosahedron [ Side : " + side + " ] ");
    System.out.print("\n Volume : " + volume + "\n\n");
  }
  public static void main(String[] args)
  {
    IcosahedronVolume obj = new IcosahedronVolume();
    //Test Cases  
    obj.icosahedron_volume(4);
    obj.icosahedron_volume(8);
    obj.icosahedron_volume(13.6);
  }
}

Output

 Icosahedron [ Side : 4.0 ]
 Volume : 139.6284793999944

 Icosahedron [ Side : 8.0 ]
 Volume : 1117.0278351999552

 Icosahedron [ Side : 13.6 ]
 Volume : 5487.95775433738
// C++ Program
// Find volume of Icosahedron
#include<iostream>
#include <math.h>
using namespace std;
class IcosahedronVolume
{
  public:
    //Calculate volume of Icosahedron by given side
    void icosahedron_volume(double side)
    {
      //Calculate Formula
      //5/12 (3 + √5)(side³)
      double volume = ((double) 5 / 12) *(3 + sqrt(5)) *(side *side *side);
      cout << " Icosahedron [ Side : " << side << " ] ";
      cout << "\n Volume : " << volume << "\n\n";
    }
};
int main()
{
  IcosahedronVolume obj =  IcosahedronVolume();
  //Test Cases  
  obj.icosahedron_volume(4);
  obj.icosahedron_volume(8);
  obj.icosahedron_volume(13.6);
  return 0;
}

Output

 Icosahedron [ Side : 4 ]
 Volume : 139.628

 Icosahedron [ Side : 8 ]
 Volume : 1117.03

 Icosahedron [ Side : 13.6 ]
 Volume : 5487.96
// C# Program
// Find volume of Icosahedron
using System;
class IcosahedronVolume
{
  //Calculate volume of Icosahedron by given side
  public void icosahedron_volume(double side)
  {
    //Calculate Formula
    //5/12 (3 + √5)(side³)
    double volume = ((double) 5 / 12) * (3 + Math.Sqrt(5)) * (side * side * side);
    Console.Write(" Icosahedron [ Side : " + side + " ] ");
    Console.Write("\n Volume : " + volume + "\n\n");
  }
  public static void Main(String[] args)
  {
    IcosahedronVolume obj = new IcosahedronVolume();
    //Test Cases  
    obj.icosahedron_volume(4);
    obj.icosahedron_volume(8);
    obj.icosahedron_volume(13.6);
  }
}

Output

 Icosahedron [ Side : 4 ]
 Volume : 139.628479399994

 Icosahedron [ Side : 8 ]
 Volume : 1117.02783519996

 Icosahedron [ Side : 13.6 ]
 Volume : 5487.95775433738
<?php
// Php Program
// Find volume of Icosahedron
class IcosahedronVolume
{
  //Calculate volume of Icosahedron by given side
  public  function icosahedron_volume($side)
  {
    //Calculate Formula
    //5/12 (3 + √5)(side³)
    $volume = (5 / 12) *(3 + sqrt(5)) *($side *$side *$side);
    //Display the result of icosahedron volume
    echo(" Icosahedron [ Side : ". $side ." ] ");
    echo("\n Volume : ". $volume ."\n\n");
  }
}

function main()
{
  $obj = new IcosahedronVolume();
  //Test Cases  
  $obj->icosahedron_volume(4);
  $obj->icosahedron_volume(8);
  $obj->icosahedron_volume(13.6);
}
main();

Output

 Icosahedron [ Side : 4 ]
 Volume : 139.62847939999

 Icosahedron [ Side : 8 ]
 Volume : 1117.0278352

 Icosahedron [ Side : 13.6 ]
 Volume : 5487.9577543374
// Node Js Program
// Find volume of Icosahedron
class IcosahedronVolume
{
  //Calculate volume of Icosahedron by given side
  icosahedron_volume(side)
  {
    //Calculate Formula
    //5/12 (3 + √5)(side³)
    var volume = (5 / 12) *(3 + Math.sqrt(5)) *(side *side *side);
    //Display the result of icosahedron volume
    process.stdout.write(" Icosahedron [ Side : " + side + " ] ");
    process.stdout.write("\n Volume : " + volume + "\n\n");
  }
}

function main(args)
{
  var obj = new IcosahedronVolume();
  //Test Cases  
  obj.icosahedron_volume(4);
  obj.icosahedron_volume(8);
  obj.icosahedron_volume(13.6);
}
main();

Output

 Icosahedron [ Side : 4 ]
 Volume : 139.6284793999944

 Icosahedron [ Side : 8 ]
 Volume : 1117.0278351999552

 Icosahedron [ Side : 13.6 ]
 Volume : 5487.95775433738
#  Python 3 Program
#  Find volume of Icosahedron
import math
class IcosahedronVolume :
  # Calculate volume of Icosahedron by given side
  def icosahedron_volume(self, side) :
    # Calculate Formula
    # 5/12 (3 + √5)(side³)
    volume = (5 / 12) * (3 + math.sqrt(5)) * (side * side * side)
    # Display the result of icosahedron volume
    print(" Icosahedron [ Side : ", side , end = " ]")
    print("\n Volume : ", volume ,"\n")
  

def main() :
  obj = IcosahedronVolume()
  # Test Cases  
  obj.icosahedron_volume(4)
  obj.icosahedron_volume(8)
  obj.icosahedron_volume(13.6)


if __name__ == "__main__": main()

Output

 Icosahedron [ Side :  4 ]
 Volume :  139.6284793999944

 Icosahedron [ Side :  8 ]
 Volume :  1117.0278351999552

 Icosahedron [ Side :  13.6 ]
 Volume :  5487.95775433738
#  Ruby Program
#  Find volume of Icosahedron
class IcosahedronVolume

  # Calculate volume of Icosahedron by given side
  def icosahedron_volume(side)
  
    # Calculate Formula
    # 5/12 (3 + √5)(side³)
    volume = (5.0 / 12) * (3 + Math.sqrt(5)) * (side * side * side)
    # Display the result of icosahedron volume
    print(" Icosahedron [ Side  : ", side ," ] ")
    print("\n Volume  : ", volume ,"\n\n")
  end
end
def main()

  obj = IcosahedronVolume.new()
  # Test Cases  
  obj.icosahedron_volume(4)
  obj.icosahedron_volume(8)
  obj.icosahedron_volume(13.6)
end
main()

Output

 Icosahedron [ Side  : 4 ] 
 Volume  : 139.6284793999944

 Icosahedron [ Side  : 8 ] 
 Volume  : 1117.0278351999552

 Icosahedron [ Side  : 13.6 ] 
 Volume  : 5487.95775433738

// Scala Program
// Find volume of Icosahedron
class IcosahedronVolume
{
  //Calculate volume of Icosahedron by given side
  def icosahedron_volume(side: Double): Unit = {
    //Calculate Formula
    //5/12 (3 + √5)(side³)
    var volume: Double = (5.0 / 12) * (3 + Math.sqrt(5)) * (side * side * side);
    //Display the result of icosahedron volume
    print(" Icosahedron [ Side : " + side + " ] ");
    print("\n Volume : " + volume + "\n\n");
  }
}
object Main
{
  def main(args: Array[String]): Unit = {
    var obj: IcosahedronVolume = new IcosahedronVolume();
    //Test Cases  
    obj.icosahedron_volume(4);
    obj.icosahedron_volume(8);
    obj.icosahedron_volume(13.6);
  }
}

Output

 Icosahedron [ Side : 4.0 ]
 Volume : 139.6284793999944

 Icosahedron [ Side : 8.0 ]
 Volume : 1117.0278351999552

 Icosahedron [ Side : 13.6 ]
 Volume : 5487.95775433738
// Swift Program
// Find volume of Icosahedron
import Foundation
class IcosahedronVolume
{
  //Calculate volume of Icosahedron by given side
  func icosahedron_volume(_ side: Double)
  {
    //Calculate Formula
    //5/12 (3 + √5)(side³)
    let volume: Double = (5 / 12) * (3 + sqrt(5)) * (side * side * side);
    //Display the result of icosahedron volume
    print(" Icosahedron [ Side : ", side , terminator: " ]");
    print("\n Volume : ", volume ,"\n");
  }
}
func main()
{
  let obj: IcosahedronVolume = IcosahedronVolume();
  //Test Cases  
  obj.icosahedron_volume(4);
  obj.icosahedron_volume(8);
  obj.icosahedron_volume(13.6);
}
main();

Output

 Icosahedron [ Side :  4.0 ]
 Volume :  139.628479399994

 Icosahedron [ Side :  8.0 ]
 Volume :  1117.02783519996

 Icosahedron [ Side :  13.6 ]
 Volume :  5487.95775433738


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