求三棱柱体体积的程序

给定三棱镜的长度、宽度和高度,任务是求出三棱镜的体积。 例如:

null
Input:  l = 18, b = 12, h = 9Output: Volume of triangular prism: 972Input: l = 10, b = 8, h = 6Output: Volume of triangular prism: 240

在数学中,三棱柱是一种三维实体形状,其两端由相等的平行线连接。三角棱镜包含5个面、9条边和6个顶点。

triangular prism

求三棱柱体体积的公式:

Volume = ( l * b * h ) / 2 

C++

// CPP program to find the volume
// of the triangular prism
#include <bits/stdc++.h>
using namespace std;
// function to find the Volume
// of triangular prism
float findVolume( float l, float b, float h)
{
// formula to find Volume
float volume = (l * b * h) / 2;
return volume;
}
// Driver Code
int main()
{
float l = 18, b = 12, h = 9;
// function calling
cout << "Volume of triangular prism: "
<< findVolume(l, b, h);
return 0;
}


JAVA

// Java program to find the volume
// of the triangular prism
import java.io.*;
class GFG {
// function to find the Volume
// of triangular prism
static float findVolume( float l, float b, float h)
{
// formula to find Volume
float volume = (l * b * h) / 2 ;
return volume;
}
// Driver code
public static void main(String[] args)
{
float l = 18 , b = 12 , h = 9 ;
// function calling
System.out.println( "Volume of triangular prism: "
+ findVolume(l, b, h));
}
}


Python3

# Python3 program to find the volume
# of the triangular prism
# function to find the Volume
# of triangular prism
def findVolume(l, b, h) :
# formula to find Volume
return ((l * b * h) / 2 )
# Driver Code
l = 18
b = 12
h = 9
# function calling
print ( "Volume of triangular prism: " ,
findVolume(l, b, h))


C#

// C# program to find the volume
// of the triangular prism
using System;
class GFG {
// function to find the Volume
// of triangular prism
static float findVolume( float l, float b, float h)
{
// formula to find Volume
float volume = (l * b * h) / 2;
return volume;
}
// Driver code
static public void Main()
{
float l = 18, b = 12, h = 9;
// function calling
Console.WriteLine( "Volume of triangular prism: "
+ findVolume(l, b, h));
}
}


PHP

<?php
// PHP program to find the volume
// of the triangular prism
// function to find the Volume
// of triangular prism
function findVolume( $l , $b , $h )
{
// formula to find Volume
$volume = ( $l * $b * $h ) / 2;
return $volume ;
}
// Driver Code
$l = 18; $b = 12; $h = 9;
// function calling
echo "Volume of triangular prism: "
. findVolume( $l , $b , $h );
?>


Javascript

<script>
// Javascript program to find the volume
// of the triangular prism
// function to find the Volume
// of triangular prism
function findVolume( l,  b, h)
{
// formula to find Volume
let volume = (l * b * h) / 2;
return volume;
}
// Driver Code
let l = 18, b = 12, h = 9;
// function calling
document.write( "Volume of triangular prism: " + findVolume(l, b, h));
// This code is contributed by todaysgaurav
</script>


输出:

Volume of triangular prism: 972

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享