📜  长方体体积和表面积的程序

📅  最后修改于: 2021-10-23 08:23:33             🧑  作者: Mango

Cuboid 是在 3 维平面上表示的 3 维盒状图形。Cuboid 有 6 个矩形面。每个面与另一个面呈90度相交。长方体的三个边在同一个顶点相交。由于它是由6个矩形面组成的,所以它有不同尺寸的长、宽和高。

长方体

例子 :

Input : 2 3 4
Output : Area = 24
         Total Surface Area = 52 
  

Input : 5 6 12
Output : Area = 360
         Total Surface Area = 324

公式:

Area = l*w*h
Total Surface Area = 2*l*w + 2*w*h + 2*l*h
where l, h, w are length, height and width of
cuboid respectively.
C++
// CPP program to find volume and
// total surface area of cuboid
#include 
using namespace std;
 
// utility function
double areaCuboid(double l, double h, double w)
{
    return (l * h * w);
}
 
double surfaceAreaCuboid(double l, double h, double w)
{
    return (2 * l * w + 2 * w * h + 2 * l * h);
}
 
// driver function
int main()
{
    double l = 1;
    double h = 5;
    double w = 7;
    cout << "Area = " << areaCuboid(l, h, w) << endl;
    cout << "Total Surface Area = "
         << surfaceAreaCuboid(l, h, w);
    return 0;
}


Java
// Java program to find volume and
// total surface area of cuboid
 
class GFG
{
    // utility function
    static double areaCuboid(double l, double h,
                                           double w)
    {
        return (l * h * w);
    }
 
    static double surfaceAreaCuboid(double l, double h,
                                                double w)
    {
        return (2 * l * w + 2 * w * h + 2 * l * h);
    }
     
    // Driver code
    public static void main (String[] args)
    {
        double l = 1;
        double h = 5;
        double w = 7;
        System.out.println("Area = " + areaCuboid(l, h, w));
        System.out.println("Total Surface Area = "
                            + surfaceAreaCuboid(l, h, w));
    }
}
// This code is contributed By Anant Agarwal.


Python3
# Python3 code to find volume and
# total surface area of cuboid
 
# utility function
def volumeCuboid( l , h , w ):
    return (l * h * w)
     
def surfaceAreaCuboid( l , h , w ):
    return (2 * l * w + 2 * w * h + 2 * l * h)
 
# driver function
l = 1
h = 5
w = 7
print("Volume =" , volumeCuboid(l, h, w))
print("Total Surface Area =", surfaceAreaCuboid(l, h, w))
 
#This code is contributed by "Sharad_Bhardwaj".


C#
// C# program to find volume and
// total surface area of cuboid
using System;
 
class GFG {
     
    // utility function
    static double areaCuboid(double l, double h,
                            double w)
    {
        return (l * h * w);
    }
 
    static double surfaceAreaCuboid(double l, double h,
                                    double w)
    {
        return (2 * l * w + 2 * w * h + 2 * l * h);
    }
 
    // Driver code
    public static void Main()
    {
        double l = 1;
        double h = 5;
        double w = 7;
         
        Console.WriteLine("Area = " + areaCuboid(l, h, w));
        Console.WriteLine("Total Surface Area = "
                        + surfaceAreaCuboid(l, h, w));
    }
}
 
// This code is contributed By vt_m.


PHP


Javascript


输出 :

Area = 35
Total Surface Area = 94