Skip to main content

Find volume of cuboid

To find the volume of a cuboid, you need to multiply its length, width, and height. Let's assume that the length of the cuboid is 5 units, the width is 4 units, and the height is 3 units. Then the volume of the cuboid would be:

Volume = length x width x height
= 5 x 4 x 3
= 60 cubic units

Therefore, the volume of the given cuboid is 60 cubic units.

Here given code implementation process.

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

//Calculate volume of cuboid by length,width and height
void cuboid_volume(double length, double width, double height)
{
	printf("\nGiven Length : %lf, Width : %lf , Height : %lf", length, width, height);
	// Formula of cuboid volume
	// (length * width * height)
	// Calculate volume of cuboid
	double result = (length * width * height);
	//Display result
	printf("\nVolume of cuboid : %lf\n", result);
}
int main()
{
	//Simple Case
	cuboid_volume(3.5, 5.5, 7.2);
	cuboid_volume(2, 3, 5);
	cuboid_volume(7, 5.4, 5);
	return 0;
}

Output

Given Length : 3.500000, Width : 5.500000 , Height : 7.200000
Volume of cuboid : 138.600000

Given Length : 2.000000, Width : 3.000000 , Height : 5.000000
Volume of cuboid : 30.000000

Given Length : 7.000000, Width : 5.400000 , Height : 5.000000
Volume of cuboid : 189.000000
// Java Program
// Find volume of cuboid
class Cuboid
{
	//Calculate volume of cuboid by length,width and height
	void volume(double length, double width, double height)
	{
		System.out.print("\nGiven Length : " + length + ", Width : " + width + " , Height : " + height);
		// Formula of cuboid volume
		// (length * width * height)
		// Calculate volume of cuboid
		double result = (length * width * height);
		// Display result
		System.out.print("\nVolume of cuboid : " + result + " \n");
	}
	public static void main(String[] args)
	{
		Cuboid obj = new Cuboid();
		//Simple Case
		obj.volume(3.5, 5.5, 7.2);
		obj.volume(2, 3, 5);
		obj.volume(7, 5.4, 5);
	}
}

Output

Given Length : 3.5, Width : 5.5 , Height : 7.2
Volume of cuboid : 138.6

Given Length : 2.0, Width : 3.0 , Height : 5.0
Volume of cuboid : 30.0

Given Length : 7.0, Width : 5.4 , Height : 5.0
Volume of cuboid : 189.00000000000003
// C++ Program
// Find volume of cuboid
#include<iostream>

using namespace std;
class Cuboid
{
	public:
		//Calculate volume of cuboid by length,width and height
		void volume(double length, double width, double height)
		{
			cout << "\nGiven Length : " << length << ", Width : " << width << " , Height : " << height;
			// Formula of cuboid volume
			// (length * width * height)
			// Calculate volume of cuboid
			double result = (length * width * height);
			cout << "\nVolume of cuboid : " << result << " \n";
		}
};
int main()
{
	Cuboid obj ;
	//Simple Case
	obj.volume(3.5, 5.5, 7.2);
	obj.volume(2, 3, 5);
	obj.volume(7, 5.4, 5);
	return 0;
}

Output

Given Length : 3.5, Width : 5.5 , Height : 7.2
Volume of cuboid : 138.6

Given Length : 2, Width : 3 , Height : 5
Volume of cuboid : 30

Given Length : 7, Width : 5.4 , Height : 5
Volume of cuboid : 189
// C# Program
// Find volume of cuboid
using System;
class Cuboid
{
	//Calculate volume of cuboid by length,width and height
	void volume(double length, double width, double height)
	{
		Console.Write("\nGiven Length : " + length + ", Width : " + width + " , Height : " + height);
		// Formula of cuboid volume
		// (length * width * height)
		// Calculate volume of cuboid
		double result = (length * width * height);
		Console.Write("\nVolume of cuboid : " + result + " \n");
	}
	public static void Main(String[] args)
	{
		Cuboid obj = new Cuboid();
		//Simple Case
		obj.volume(3.5, 5.5, 7.2);
		obj.volume(2, 3, 5);
		obj.volume(7, 5.4, 5);
	}
}

Output

Given Length : 3.5, Width : 5.5 , Height : 7.2
Volume of cuboid : 138.6

Given Length : 2, Width : 3 , Height : 5
Volume of cuboid : 30

Given Length : 7, Width : 5.4 , Height : 5
Volume of cuboid : 189
<?php
// Php Program
// Find volume of cuboid
class Cuboid
{
	//Calculate volume of cuboid by length,width and height
	function volume($length, $width, $height)
	{
		echo "\nGiven Length : ". $length .", Width : ". $width ." , Height : ". $height;
		// Formula of cuboid volume
		// (length * width * height)
		// Calculate volume of cuboid
		$result = ($length * $width * $height);
		echo "\nVolume of cuboid : ". $result ." \n";
	}
}

function main()
{
	$obj = new Cuboid();
	//Simple Case
	$obj->volume(3.5, 5.5, 7.2);
	$obj->volume(2, 3, 5);
	$obj->volume(7, 5.4, 5);
}
main();

Output

Given Length : 3.5, Width : 5.5 , Height : 7.2
Volume of cuboid : 138.6

Given Length : 2, Width : 3 , Height : 5
Volume of cuboid : 30

Given Length : 7, Width : 5.4 , Height : 5
Volume of cuboid : 189
// Node Js Program
// Find volume of cuboid
class Cuboid
{
	//Calculate volume of cuboid by length,width and height
	volume(length, width, height)
	{
		process.stdout.write("\nGiven Length : " + length + ", Width : " + width + " , Height : " + height);
		// Formula of cuboid volume
		// (length * width * height)
		// Calculate volume of cuboid
		var result = (length * width * height);
		process.stdout.write("\nVolume of cuboid : " + result + " \n");
	}
}

function main()
{
	var obj = new Cuboid();
	//Simple Case
	obj.volume(3.5, 5.5, 7.2);
	obj.volume(2, 3, 5);
	obj.volume(7, 5.4, 5);
}
main();

Output

Given Length : 3.5, Width : 5.5 , Height : 7.2
Volume of cuboid : 138.6

Given Length : 2, Width : 3 , Height : 5
Volume of cuboid : 30

Given Length : 7, Width : 5.4 , Height : 5
Volume of cuboid : 189.00000000000003
#  Python 3 Program
#  Find volume of cuboid
class Cuboid :
	# Calculate volume of cuboid by length,width and height
	def volume(self, length, width, height) :
		print("\nGiven Length : ", length ,", Width : ", width ," , Height : ", height, end = "")
		#  Formula of cuboid volume
		#  (length * width * height)
		#  Calculate volume of cuboid
		result = (length * width * height)
		print("\nVolume of cuboid : ", result ," \n", end = "")
	

def main() :
	obj = Cuboid()
	# Simple Case
	obj.volume(3.5, 5.5, 7.2)
	obj.volume(2, 3, 5)
	obj.volume(7, 5.4, 5)

if __name__ == "__main__": main()

Output

Given Length :  3.5 , Width :  5.5  , Height :  7.2
Volume of cuboid :  138.6

Given Length :  2 , Width :  3  , Height :  5
Volume of cuboid :  30

Given Length :  7 , Width :  5.4  , Height :  5
Volume of cuboid :  189.00000000000003
#  Ruby Program
#  Find volume of cuboid
class Cuboid

	# Calculate volume of cuboid by length,width and height
	def volume(length, width, height)
	
		print("\nGiven Length : ", length ,", Width : ", width ," , Height : ", height)
		#  Formula of cuboid volume
		#  (length * width * height)
		#  Calculate volume of cuboid
		result = (length * width * height)
		#  Display result
		print("\nVolume of cuboid : ", result ," \n")
	end
end
def main()

	obj = Cuboid.new()
	# Simple Case
	obj.volume(3.5, 5.5, 7.2)
	obj.volume(2, 3, 5)
	obj.volume(7, 5.4, 5)
end
main()

Output

Given Length : 3.5, Width : 5.5 , Height : 7.2
Volume of cuboid : 138.6 

Given Length : 2, Width : 3 , Height : 5
Volume of cuboid : 30 

Given Length : 7, Width : 5.4 , Height : 5
Volume of cuboid : 189.00000000000003 
// Scala Program
// Find volume of cuboid
class Cuboid
{
	//Calculate volume of cuboid by length,width and height
	def volume(length: Double, width: Double, height: Double): Unit = {
		print("\nGiven Length : " + length + ", Width : " + width + " , Height : " + height);
		// Formula of cuboid volume
		// (length * width * height)
		// Calculate volume of cuboid
		var result: Double = (length * width * height);
		// Display result
		print("\nVolume of cuboid : " + result + " \n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: Cuboid = new Cuboid();
		//Simple Case
		obj.volume(3.5, 5.5, 7.2);
		obj.volume(2, 3, 5);
		obj.volume(7, 5.4, 5);
	}
}

Output

Given Length : 3.5, Width : 5.5 , Height : 7.2
Volume of cuboid : 138.6

Given Length : 2.0, Width : 3.0 , Height : 5.0
Volume of cuboid : 30.0

Given Length : 7.0, Width : 5.4 , Height : 5.0
Volume of cuboid : 189.00000000000003
// Swift Program
// Find volume of cuboid
class Cuboid
{
	//Calculate volume of cuboid by length,width and height
	func volume(_ length: Double, _ width: Double, _ height: Double)
	{
		print("\nGiven Length : ", length ,", Width : ", width ," , Height : ", height, terminator: "");
		// Formula of cuboid volume
		// (length * width * height)
		// Calculate volume of cuboid
		let result: Double = (length * width * height);
		print("\nVolume of cuboid : ", result ," \n", terminator: "");
	}
}
func main()
{
	let obj: Cuboid = Cuboid();
	//Simple Case
	obj.volume(3.5, 5.5, 7.2);
	obj.volume(2, 3, 5);
	obj.volume(7, 5.4, 5);
}
main();

Output

Given Length :  3.5 , Width :  5.5  , Height :  7.2
Volume of cuboid :  138.6

Given Length :  2.0 , Width :  3.0  , Height :  5.0
Volume of cuboid :  30.0

Given Length :  7.0 , Width :  5.4  , Height :  5.0
Volume of cuboid :  189.0




Comment

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