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

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

立方体是在 3 维平面上表示的 3 维盒状图形。立方体有 6 个正方形的相等面。每张脸都以 90 度与另一张脸相遇。立方体的三个边在同一个顶点相交。

立方体

例子:

Input : Side of a cube = 2
Output : Area = 8
         Total surface area = 24

Input : Side of a cube = 3
Output : Area = 27
         Total surface area = 54

C++
// CPP program to find area
// and total surface area of cube
#include 
using namespace std;
 
// utility function
double areaCube(double a)
{
    return (a * a * a);
}
 
double surfaceCube(double a)
{
    return (6 * a * a);
}
 
// driver function
int main()
{
    double a = 5;
    cout << "Area = " << areaCube(a) << endl;
    cout << "Total surface area = " << surfaceCube(a);
    return 0;
}


Java
// Java program to find area
// and total surface area of cube
 
class GFG
{
    // utility function
    static double areaCube(double a)
    {
        return (a * a * a);
    }
 
    static double surfaceCube(double a)
    {
        return (6 * a * a);
    }
     
    // Driver code
    public static void main (String[] args)
    {
        double a = 5;
        System.out.println("Area = "+areaCube(a));
        System.out.println("Total surface area = "
                           +surfaceCube(a));
    }
}
 
// This code is contributed by Anant Agarwal.


Python3
# Python3 code to find area
# and total surface area of cube
 
# utility function
def areaCube( a ):
    return (a * a * a)
 
def surfaceCube( a ):
    return (6 * a * a)
 
# driver function
a = 5
print("Area =", areaCube(a))
print("Total surface area =", surfaceCube(a))
 
# This code is contributed by "Sharad_Bhardwaj".


C#
// C# program to find area
// and total surface area of cube
using System;
 
class GFG {
     
    // utility function
    static double areaCube(double a)
    {
        return (a * a * a);
    }
 
    static double surfaceCube(double a)
    {
        return (6 * a * a);
    }
 
    // Driver code
    public static void Main()
    {
        double a = 5;
         
        Console.WriteLine("Area = " + areaCube(a));
        Console.WriteLine("Total surface area = "
                        + surfaceCube(a));
    }
}
 
// This code is contributed by vt_m.


PHP


Javascript


输出:

Area = 125
Total surface area = 150