Find volume of Hemisphere

Here given code implementation process.

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

#include <math.h>

//Calculate volume of hemisphere by radius
void hemisphere_volume(double r)
{
  printf("\nGiven radius : %lf", r);
  // Formula of hemisphere volume
  //   2πr³
  //  -----
  //    3
  //Calculate volume of hemisphere
  double volume = (2 * M_PI * (r * r * r)) / 3;
  printf("\nVolume of hemisphere : %lf\n", volume);
}
int main()
{
  //Simple Case
  hemisphere_volume(13);
  hemisphere_volume(4);
  hemisphere_volume(3.5);
  return 0;
}

Output

Given radius : 13.000000
Volume of hemisphere : 4601.386040

Given radius : 4.000000
Volume of hemisphere : 134.041287

Given radius : 3.500000
Volume of hemisphere : 89.797190
// Java Program
// Find volume of Hemisphere
class Hemisphere
{
  //Calculate volume of hemisphere by radius
  public void hemisphere_volume(double r)
  {
    System.out.print("\nGiven radius : " + r);
    // Formula of hemisphere volume
    //   2πr³
    //  -----
    //    3
    //Calculate volume of hemisphere
    double volume = (2 * Math.PI * (r * r * r)) / 3;
    System.out.print("\nVolume of of hemisphere : " + volume + "\n");
  }
  public static void main(String[] args)
  {
    Hemisphere obj = new Hemisphere();
    //Simple Case
    obj.hemisphere_volume(13);
    obj.hemisphere_volume(4);
    obj.hemisphere_volume(3.5);
  }
}

Output

Given radius : 13.0
Volume of of hemisphere : 4601.386039957851

Given radius : 4.0
Volume of of hemisphere : 134.0412865531645

Given radius : 3.5
Volume of of hemisphere : 89.79719001510826
// C++ Program
// Find volume of Hemisphere
#include<iostream>
#include<math.h>
using namespace std;
class Hemisphere
{
  public:
    //Calculate volume of hemisphere by radius
    void hemisphere_volume(double r)
    {
      cout << "\nGiven radius : " << r;
      // Formula of hemisphere volume
      //   2πr³
      //  -----
      //    3
      //Calculate volume of hemisphere
      double volume = (2 * M_PI * (r * r * r)) / 3;
      cout << "\nVolume of of hemisphere : " << volume << "\n";
    }
};
int main()
{
  Hemisphere obj ;
  //Simple Case
  obj.hemisphere_volume(13);
  obj.hemisphere_volume(4);
  obj.hemisphere_volume(3.5);
  return 0;
}

Output

Given radius : 13
Volume of of hemisphere : 4601.39

Given radius : 4
Volume of of hemisphere : 134.041

Given radius : 3.5
Volume of of hemisphere : 89.7972
// C# Program
// Find volume of Hemisphere
using System;
class Hemisphere
{
  //Calculate volume of hemisphere by radius
  public void hemisphere_volume(double r)
  {
    Console.Write("\nGiven radius : " + r);
    // Formula of hemisphere volume
    //   2πr³
    //  -----
    //    3
    //Calculate volume of hemisphere
    double volume = (2 * Math.PI * (r * r * r)) / 3;
    Console.Write("\nVolume of of hemisphere : " + volume + "\n");
  }
  public static void Main(String[] args)
  {
    Hemisphere obj = new Hemisphere();
    //Simple Case
    obj.hemisphere_volume(13);
    obj.hemisphere_volume(4);
    obj.hemisphere_volume(3.5);
  }
}

Output

Given radius : 13
Volume of of hemisphere : 4601.38603995785

Given radius : 4
Volume of of hemisphere : 134.041286553164

Given radius : 3.5
Volume of of hemisphere : 89.7971900151083
<?php
// Php Program
// Find volume of Hemisphere
class Hemisphere
{
  //Calculate volume of hemisphere by radius
  public  function hemisphere_volume($r)
  {
    echo "\nGiven radius : ". $r;
    // Formula of hemisphere volume
    //   2πr³
    //  -----
    //    3
    //Calculate volume of hemisphere
    $volume = (2 * M_PI * ($r * $r * $r)) / 3;
    echo "\nVolume of of hemisphere : ". $volume ."\n";
  }
}

function main()
{
  $obj = new Hemisphere();
  //Simple Case
  $obj->hemisphere_volume(13);
  $obj->hemisphere_volume(4);
  $obj->hemisphere_volume(3.5);
}
main();

Output

Given radius : 13
Volume of of hemisphere : 4601.3860399579

Given radius : 4
Volume of of hemisphere : 134.04128655316

Given radius : 3.5
Volume of of hemisphere : 89.797190015108
// Node Js Program
// Find volume of Hemisphere
class Hemisphere
{
  //Calculate volume of hemisphere by radius
  hemisphere_volume(r)
  {
    process.stdout.write("\nGiven radius : " + r);
    // Formula of hemisphere volume
    //   2πr³
    //  -----
    //    3
    //Calculate volume of hemisphere
    var volume = (2 * Math.PI * (r * r * r)) / 3;
    process.stdout.write("\nVolume of of hemisphere : " + volume + "\n");
  }
}

function main()
{
  var obj = new Hemisphere();
  //Simple Case
  obj.hemisphere_volume(13);
  obj.hemisphere_volume(4);
  obj.hemisphere_volume(3.5);
}
main();

Output

Given radius : 13
Volume of of hemisphere : 4601.386039957851

Given radius : 4
Volume of of hemisphere : 134.0412865531645

Given radius : 3.5
Volume of of hemisphere : 89.79719001510826
#  Python 3 Program
#  Find volume of Hemisphere
import math
class Hemisphere :
  # Calculate volume of hemisphere by radius
  def hemisphere_volume(self, r) :
    print("\nGiven radius : ", r, end = "")
    #  Formula of hemisphere volume
    #    2πr³
    #   -----
    #     3
    # Calculate volume of hemisphere
    volume = (2 * math.pi * (r * r * r)) / 3
    print("\nVolume of of hemisphere : ", volume ,"\n", end = "")
  

def main() :
  obj = Hemisphere()
  # Simple Case
  obj.hemisphere_volume(13)
  obj.hemisphere_volume(4)
  obj.hemisphere_volume(3.5)

if __name__ == "__main__": main()

Output

Given radius :  13
Volume of of hemisphere :  4601.386039957851

Given radius :  4
Volume of of hemisphere :  134.0412865531645

Given radius :  3.5
Volume of of hemisphere :  89.79719001510826
#  Ruby Program
#  Find volume of Hemisphere
class Hemisphere

  # Calculate volume of hemisphere by radius
  def hemisphere_volume(r)
  
    print("\nGiven radius : ", r)
    #  Formula of hemisphere volume
    #    2πr³
    #   -----
    #     3
    # Calculate volume of hemisphere
    volume = (2 * Math::PI * (r * r * r)) / 3
    print("\nVolume of of hemisphere : ", volume ,"\n")
  end
end
def main()

  obj = Hemisphere.new()
  # Simple Case
  obj.hemisphere_volume(13)
  obj.hemisphere_volume(4)
  obj.hemisphere_volume(3.5)
end
main()

Output

Given radius : 13
Volume of of hemisphere : 4601.386039957851

Given radius : 4
Volume of of hemisphere : 134.0412865531645

Given radius : 3.5
Volume of of hemisphere : 89.79719001510826
// Scala Program
// Find volume of Hemisphere
class Hemisphere
{
  //Calculate volume of hemisphere by radius
  def hemisphere_volume(r: Double): Unit = {
    print("\nGiven radius : " + r);
    // Formula of hemisphere volume
    //   2πr³
    //  -----
    //    3
    //Calculate volume of hemisphere
    var volume: Double = (2 * Math.PI * (r * r * r)) / 3;
    print("\nVolume of of hemisphere : " + volume + "\n");
  }
}
object Main
{
  def main(args: Array[String]): Unit = {
    var obj: Hemisphere = new Hemisphere();
    //Simple Case
    obj.hemisphere_volume(13);
    obj.hemisphere_volume(4);
    obj.hemisphere_volume(3.5);
  }
}

Output

Given radius : 13.0
Volume of of hemisphere : 4601.386039957851

Given radius : 4.0
Volume of of hemisphere : 134.0412865531645

Given radius : 3.5
Volume of of hemisphere : 89.79719001510826
// Swift Program
// Find volume of Hemisphere
import Foundation
class Hemisphere
{
  //Calculate volume of hemisphere by radius
  func hemisphere_volume(_ r: Double)
  {
    print("\nGiven radius : ", r, terminator: "");
    // Formula of hemisphere volume
    //   2πr³
    //  -----
    //    3
    //Calculate volume of hemisphere
    let volume: Double = (2 * Double.pi * (r * r * r)) / 3;
    print("\nVolume of of hemisphere : ", volume ,"\n", terminator: "");
  }
}
func main()
{
  let obj: Hemisphere = Hemisphere();
  //Simple Case
  obj.hemisphere_volume(13);
  obj.hemisphere_volume(4);
  obj.hemisphere_volume(3.5);
}
main();

Output

Given radius :  13.0
Volume of of hemisphere :  4601.38603995785

Given radius :  4.0
Volume of of hemisphere :  134.041286553164

Given radius :  3.5
Volume of of hemisphere :  89.7971900151083


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