用C++編寫尋找平行四邊形面積的程式


在這個問題中,我們被給定兩個值,表示平行四邊形的底邊和高。我們的任務是用C++建立一個程式來查詢平行四邊形的面積。

平行四邊形是一個四邊形,其中相對的邊相等且相互平行。

讓我們舉個例子來理解這個問題,

輸入

B = 20, H = 15

輸出

300

解釋

平行四邊形的面積=底邊*高=20*15=300

解決方案途徑

為了解決問題,我們將使用平行四邊形面積的幾何公式,

Area = base * height.

為了說明我們解決方案的工作原理的程式,

例子

 線上演示

#include <iostream>
using namespace std;
float calcParallelogramArea(float B, float H){
   return (B * H);
}
int main() {
   float B = 20, H = 15;
   cout<<"The area of parallelogram with base "<<B<<" and height "<<H<<" is
   "<<calcParallelogramArea(B, H);
   return 0;
}

輸出

The area of parallelogram with base 20 and height 15 is 300

更新於: 2020 年 9 月 16 日

317 次檢視

開啟您的事業生涯

透過完成課程獲得認證

立即開始
廣告