C++ 中平行四邊形內三角形面積


形狀的面積是形狀在二維平面內的範圍。

三角形是有三條邊的多邊形。

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

在此程式中,有一個平行四邊形,它的底邊和高度與它同時刻畫一個三角形,其底邊與平行四邊形相同。我們需要使用給定的底邊和高度計算三角形的面積。

已構造三角形的面積取平行四邊形的底邊及其公共高度,該高度按公式表示 = 0.5 * 底邊 * 高度

area = ½ * b * h

示例

 線上演示

#include<iostream>
#include<math.h>
using namespace std;
int main(){
   float b, h, Area;
   b = 30.0;
   h = 22.0;
   Area = (0.5 * b * h);
   cout<<"Area of triangle with base "<<b<<" and height "<<h<<" is "<<Area;
   return 0;
}

輸出

Area of triangle with base 30 and height 22 is 330

更新於: 24-Oct-2019

368 次瀏覽

啟動您的 職業生涯

完成課程,獲得認證

開始
廣告
© . All rights reserved.