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
广告