Find the volume of a cone

Here given code implementation process.

//C Program
//Find the volume of a cone
#include <stdio.h>

#include <math.h>
 //Calculate volume of cone by given r and height
void cone_volume(double r, double h)
{
	// Formula
	// πr²h/3
	// Here h is height and r is radius
	double volume = M_PI * (r * r) * h / 3;
	//Display result
	printf(" Cone Size [ r : %lf  h : %lf] ", r, h);
	printf("\n Volume : %lf\n\n", volume);
}
int main()
{
	//Test Case
	cone_volume(5, 3);
	cone_volume(9, 5);
	cone_volume(4, 6.2);
	cone_volume(6.7, 7.3);
	return 0;
}

Output

 Cone Size [ r : 5.000000  h : 3.000000]
 Volume : 78.539816

 Cone Size [ r : 9.000000  h : 5.000000]
 Volume : 424.115008

 Cone Size [ r : 4.000000  h : 6.200000]
 Volume : 103.881997

 Cone Size [ r : 6.700000  h : 7.300000]
 Volume : 343.163496
// Java Program
// Find the volume of a cone
class Cone
{
	//Calculate volume of cone by given r and height
	public void cone_volume(double r, double h)
	{
		// Formula
		// πr²h/3
		// Here h is height and r is radius
		double volume = Math.PI * (r * r) * h / 3;
		//Display result
		System.out.print(" Cone Size [ r : " + r + " h : " + h + "] ");
		System.out.print("\n Volume : " + volume + "\n\n");
	}
	public static void main(String[] args)
	{
		Cone obj = new Cone();
		//Test Case
		obj.cone_volume(5, 3);
		obj.cone_volume(9, 5);
		obj.cone_volume(4, 6.2);
		obj.cone_volume(6.7, 7.3);
	}
}

Output

 Cone Size [ r : 5.0 h : 3.0]
 Volume : 78.53981633974483

 Cone Size [ r : 9.0 h : 5.0]
 Volume : 424.11500823462205

 Cone Size [ r : 4.0 h : 6.2]
 Volume : 103.8819970787025

 Cone Size [ r : 6.7 h : 7.3]
 Volume : 343.1634959344715
// C++ Program
// Find the volume of a cone
#include<iostream>
#include <math.h>
using namespace std;
class Cone
{
	public:
		//Calculate volume of cone by given r and height
		void cone_volume(double r, double h)
		{
			// Formula
			// πr²h/3
			// Here h is height and r is radius
			double volume = M_PI *(r *r) *h / 3;
			cout << " Cone Size [ r : " << r << " h : " << h << "] ";
			cout << "\n Volume : " << volume << "\n\n";
		}
};
int main()
{
	Cone obj ;
	//Test Case
	obj.cone_volume(5, 3);
	obj.cone_volume(9, 5);
	obj.cone_volume(4, 6.2);
	obj.cone_volume(6.7, 7.3);
	return 0;
}

Output

 Cone Size [ r : 5 h : 3]
 Volume : 78.5398

 Cone Size [ r : 9 h : 5]
 Volume : 424.115

 Cone Size [ r : 4 h : 6.2]
 Volume : 103.882

 Cone Size [ r : 6.7 h : 7.3]
 Volume : 343.163
// C# Program
// Find the volume of a cone
using System;
class Cone
{
	//Calculate volume of cone by given r and height
	public void cone_volume(double r, double h)
	{
		// Formula
		// πr²h/3
		// Here h is height and r is radius
		double volume = Math.PI * (r * r) * h / 3;
		Console.Write(" Cone Size [ r : " + r + " h : " + h + "] ");
		Console.Write("\n Volume : " + volume + "\n\n");
	}
	public static void Main(String[] args)
	{
		Cone obj = new Cone();
		//Test Case
		obj.cone_volume(5, 3);
		obj.cone_volume(9, 5);
		obj.cone_volume(4, 6.2);
		obj.cone_volume(6.7, 7.3);
	}
}

Output

 Cone Size [ r : 5 h : 3]
 Volume : 78.5398163397448

 Cone Size [ r : 9 h : 5]
 Volume : 424.115008234622

 Cone Size [ r : 4 h : 6.2]
 Volume : 103.881997078702

 Cone Size [ r : 6.7 h : 7.3]
 Volume : 343.163495934471
<?php
// Php Program
// Find the volume of a cone
class Cone
{
	//Calculate volume of cone by given r and height
	public 	function cone_volume($r, $h)
	{
		// Formula
		// πr²h/3
		// Here h is height and r is radius
		$volume = M_PI *($r *$r) *$h / 3;
		//Display result
		echo(" Cone Size [ r : ". $r ." h : ". $h ."] ");
		echo("\n Volume : ". $volume ."\n\n");
	}
}

function main()
{
	$obj = new Cone();
	//Test Case
	$obj->cone_volume(5, 3);
	$obj->cone_volume(9, 5);
	$obj->cone_volume(4, 6.2);
	$obj->cone_volume(6.7, 7.3);
}
main();

Output

 Cone Size [ r : 5 h : 3]
 Volume : 78.539816339745

 Cone Size [ r : 9 h : 5]
 Volume : 424.11500823462

 Cone Size [ r : 4 h : 6.2]
 Volume : 103.8819970787

 Cone Size [ r : 6.7 h : 7.3]
 Volume : 343.16349593447
// Node Js Program
// Find the volume of a cone
class Cone
{
	//Calculate volume of cone by given r and height
	cone_volume(r, h)
	{
		// Formula
		// πr²h/3
		// Here h is height and r is radius
		var volume = Math.PI *(r *r) *h / 3;
		//Display result
		process.stdout.write(" Cone Size [ r : " + r + " h : " + h + "] ");
		process.stdout.write("\n Volume : " + volume + "\n\n");
	}
}

function main(args)
{
	var obj = new Cone();
	//Test Case
	obj.cone_volume(5, 3);
	obj.cone_volume(9, 5);
	obj.cone_volume(4, 6.2);
	obj.cone_volume(6.7, 7.3);
}
main();

Output

 Cone Size [ r : 5 h : 3]
 Volume : 78.53981633974483

 Cone Size [ r : 9 h : 5]
 Volume : 424.11500823462205

 Cone Size [ r : 4 h : 6.2]
 Volume : 103.8819970787025

 Cone Size [ r : 6.7 h : 7.3]
 Volume : 343.1634959344715
#  Python 3 Program
#  Find the volume of a cone
import math
class Cone :
	# Calculate volume of cone by given r and height
	def cone_volume(self, r, h) :
		#  Formula
		#  πr²h/3
		#  Here h is height and r is radius
		volume = math.pi * (r * r) * h / 3
		# Display result
		print(" Cone Size [ r : ", r ," h : ", h ,"] ", end = "")
		print("\n Volume : ", volume ,"\n\n", end = "")
	

def main() :
	obj = Cone()
	# Test Case
	obj.cone_volume(5, 3)
	obj.cone_volume(9, 5)
	obj.cone_volume(4, 6.2)
	obj.cone_volume(6.7, 7.3)


if __name__ == "__main__": main()

Output

 Cone Size [ r :  5  h :  3 ]
 Volume :  78.53981633974483

 Cone Size [ r :  9  h :  5 ]
 Volume :  424.11500823462205

 Cone Size [ r :  4  h :  6.2 ]
 Volume :  103.8819970787025

 Cone Size [ r :  6.7  h :  7.3 ]
 Volume :  343.1634959344715
#  Ruby Program
#  Find the volume of a cone
class Cone

	# Calculate volume of cone by given r and height
	def cone_volume(r, h)
	
		#  Formula
		#  πr²h/3
		#  Here h is height and r is radius
		volume = Math::PI * (r * r) * h / 3
		# Display result
		print(" Cone Size [ r  : ", r ," h  : ", h ,"] ")
		print("\n Volume  : ", volume ,"\n\n")
	end
end
def main()

	obj = Cone.new()
	# Test Case
	obj.cone_volume(5, 3)
	obj.cone_volume(9, 5)
	obj.cone_volume(4, 6.2)
	obj.cone_volume(6.7, 7.3)
end
main()

Output

 Cone Size [ r  : 5 h  : 3] 
 Volume  : 78.53981633974483

 Cone Size [ r  : 9 h  : 5] 
 Volume  : 424.11500823462205

 Cone Size [ r  : 4 h  : 6.2] 
 Volume  : 103.8819970787025

 Cone Size [ r  : 6.7 h  : 7.3] 
 Volume  : 343.1634959344715

// Scala Program
// Find the volume of a cone
class Cone
{
	//Calculate volume of cone by given r and height
	def cone_volume(r: Double, h: Double): Unit = {
		// Formula
		// πr²h/3
		// Here h is height and r is radius
		var volume: Double = Math.PI * (r * r) * h / 3;
		//Display result
		print(" Cone Size [ r : " + r + " h : " + h + "] ");
		print("\n Volume : " + volume + "\n\n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: Cone = new Cone();
		//Test Case
		obj.cone_volume(5, 3);
		obj.cone_volume(9, 5);
		obj.cone_volume(4, 6.2);
		obj.cone_volume(6.7, 7.3);
	}
}

Output

 Cone Size [ r : 5.0 h : 3.0]
 Volume : 78.53981633974483

 Cone Size [ r : 9.0 h : 5.0]
 Volume : 424.11500823462205

 Cone Size [ r : 4.0 h : 6.2]
 Volume : 103.8819970787025

 Cone Size [ r : 6.7 h : 7.3]
 Volume : 343.1634959344715
// Swift Program
// Find the volume of a cone
class Cone
{
	//Calculate volume of cone by given r and height
	func cone_volume(_ r: Double, _ h: Double)
	{
		// Formula
		// πr²h/3
		// Here h is height and r is radius
		let volume: Double = Double.pi * (r * r) * h / 3;
		//Display result
		print(" Cone Size [ r : ", r ," h : ", h ,"] ");
		print(" Volume : ", volume ,"\n");
	}
}
func main()
{
	let obj: Cone = Cone();
	//Test Case
	obj.cone_volume(5, 3);
	obj.cone_volume(9, 5);
	obj.cone_volume(4, 6.2);
	obj.cone_volume(6.7, 7.3);
}
main();

Output

 Cone Size [ r :  5.0  h :  3.0 ]
 Volume :  78.5398163397448

 Cone Size [ r :  9.0  h :  5.0 ]
 Volume :  424.115008234622

 Cone Size [ r :  4.0  h :  6.2 ]
 Volume :  103.881997078702

 Cone Size [ r :  6.7  h :  7.3 ]
 Volume :  343.163495934471


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