Find the volume of a cylinder

Here given code implementation process.

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

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

Output

 Cylinder Size [ r : 4.200000  height : 7.000000]
 Volume : 387.923861

 Cylinder Size [ r : 9.000000  height : 5.000000]
 Volume : 1272.345025

 Cylinder Size [ r : 4.000000  height : 6.200000]
 Volume : 311.645991

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

Output

 Cylinder Size [ r : 4.2 height : 7.0]
 Volume : 387.92386086526767

 Cylinder Size [ r : 9.0 height : 5.0]
 Volume : 1272.345024703866

 Cylinder Size [ r : 4.0 height : 6.2]
 Volume : 311.6459912361075

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

Output

 Cylinder Size [ r : 4.2 height : 7]
 Volume : 387.924

 Cylinder Size [ r : 9 height : 5]
 Volume : 1272.35

 Cylinder Size [ r : 4 height : 6.2]
 Volume : 311.646

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

Output

 Cylinder Size [ r : 4.2 height : 7]
 Volume : 387.923860865268

 Cylinder Size [ r : 9 height : 5]
 Volume : 1272.34502470387

 Cylinder Size [ r : 4 height : 6.2]
 Volume : 311.645991236107

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

function main()
{
	$obj = new Cylinder();
	//Test Case
	$obj->cylinder_volume(4.2, 7);
	$obj->cylinder_volume(9, 5);
	$obj->cylinder_volume(4, 6.2);
	$obj->cylinder_volume(6.7, 7.3);
}
main();

Output

 Cylinder Size [ r : 4.2 height : 7]
 Volume : 387.92386086527

 Cylinder Size [ r : 9 height : 5]
 Volume : 1272.3450247039

 Cylinder Size [ r : 4 height : 6.2]
 Volume : 311.64599123611

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

function main(args)
{
	var obj = new Cylinder();
	//Test Case
	obj.cylinder_volume(4.2, 7);
	obj.cylinder_volume(9, 5);
	obj.cylinder_volume(4, 6.2);
	obj.cylinder_volume(6.7, 7.3);
}
main();

Output

 Cylinder Size [ r : 4.2 height : 7]
 Volume : 387.92386086526767

 Cylinder Size [ r : 9 height : 5]
 Volume : 1272.345024703866

 Cylinder Size [ r : 4 height : 6.2]
 Volume : 311.6459912361075

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

def main() :
	obj = Cylinder()
	# Test Case
	obj.cylinder_volume(4.2, 7)
	obj.cylinder_volume(9, 5)
	obj.cylinder_volume(4, 6.2)
	obj.cylinder_volume(6.7, 7.3)


if __name__ == "__main__": main()

Output

 Cylinder Size [ r :  4.2  height :  7 ]
 Volume :  387.92386086526767

 Cylinder Size [ r :  9  height :  5 ]
 Volume :  1272.345024703866

 Cylinder Size [ r :  4  height :  6.2 ]
 Volume :  311.6459912361075

 Cylinder Size [ r :  6.7  height :  7.3 ]
 Volume :  1029.4904878034145
#  Ruby Program
#  Find the volume of a cylinder
class Cylinder

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

	obj = Cylinder.new()
	# Test Case
	obj.cylinder_volume(4.2, 7)
	obj.cylinder_volume(9, 5)
	obj.cylinder_volume(4, 6.2)
	obj.cylinder_volume(6.7, 7.3)
end
main()

Output

 Cylinder Size [ r  : 4.2 height  : 7] 
 Volume  : 387.92386086526767

 Cylinder Size [ r  : 9 height  : 5] 
 Volume  : 1272.345024703866

 Cylinder Size [ r  : 4 height  : 6.2] 
 Volume  : 311.6459912361075

 Cylinder Size [ r  : 6.7 height  : 7.3] 
 Volume  : 1029.4904878034145

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

Output

 Cylinder Size [ r : 4.2 height : 7.0]
 Volume : 387.92386086526767

 Cylinder Size [ r : 9.0 height : 5.0]
 Volume : 1272.345024703866

 Cylinder Size [ r : 4.0 height : 6.2]
 Volume : 311.6459912361075

 Cylinder Size [ r : 6.7 height : 7.3]
 Volume : 1029.4904878034145
// Swift Program
// Find the volume of a cylinder

class Cylinder
{
	//Calculate volume of cylinder by given r and height
	func cylinder_volume(_ r: Double, _ height: Double)
	{
		// Formula
		// πr²h
		// Here h is height and r is radius
		let volume: Double = Double.pi * (r * r) * height;
		//Display result
		print(" Cylinder Size [ r : ", r ," height : ", height ,"] ", terminator: "");
		print("\n Volume : ", volume ,"\n\n", terminator: "");
	}
}
func main()
{
	let obj: Cylinder = Cylinder();
	//Test Case
	obj.cylinder_volume(4.2, 7);
	obj.cylinder_volume(9, 5);
	obj.cylinder_volume(4, 6.2);
	obj.cylinder_volume(6.7, 7.3);
}
main();

Output

 Cylinder Size [ r :  4.2  height :  7.0 ]
 Volume :  387.923860865268

 Cylinder Size [ r :  9.0  height :  5.0 ]
 Volume :  1272.34502470387

 Cylinder Size [ r :  4.0  height :  6.2 ]
 Volume :  311.645991236107

 Cylinder Size [ r :  6.7  height :  7.3 ]
 Volume :  1029.49048780341


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