C++長方體體積和表面積程式
什麼是長方體?
長方體是一個三維物體,具有六個矩形面,這意味著它具有不同長度和寬度的邊。長方體和立方體的區別在於,立方體的長度、高度和寬度相等,而長方體的這三個維度不相等。
長方體的屬性:
- 六個面
- 十二條稜
- 八個頂點
以下是立方體的圖形

問題
給定長、寬和體積,任務是求長方體的總表面積和體積,其中表面積是由面所佔的空間,體積是形狀可以容納的空間。
計算長方體的表面積和體積的公式如下:
表面積 = 2(長*寬 + 寬*高 + 長*高)
體積 = 長*寬*高
示例
Input-: L=3 H=2 W=3 Output-: Volume of cuboid is: 18 Total Surface Area of cuboid is: 42
演算法
Start Step 1 -> declare function to find volume of cuboid double volume(double l, double h, double w) return (l*h*w) Step 2 -> declare function to find area of cuboid double surface_area(double l, double h, double w) return (2 * l * w + 2 * w * h + 2 * l * h) Step 3 -> In main() Declare variable double l=3, h=2 and w=3 Print volume(l,h,w) Print surface_area(l, h ,w) Stop
示例
#include <bits/stdc++.h>
using namespace std;
//function for volume of cuboid
double volume(double l, double h, double w){
return (l * h * w);
}
//function for total surface area of cuboid
double surface_area(double l, double h, double w){
return (2 * l * w + 2 * w * h + 2 * l * h);
}
int main(){
double l = 3;
double h = 2;
double w = 3;
cout << "Volume of cuboid is: " <<volume(l, h, w) << endl;
cout << "Total Surface Area of cuboid is: "<< surface_area(l, h, w);
return 0;
}輸出
Volume of cuboid is: 18 Total Surface Area of cuboid is: 42
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP