在 C++ 中求三角形的周长
在这个问题中,我们将了解三角形的周长、不同类型三角形的周长公式以及计算它们的程序。
周长定义为图形周围的总距离。基本上,它是给定图形所有边的总和。
三角形的周长
三角形的周长是其三条边之和(三角形是一个三边形)。
公式:
Perimeter = sum of all sides

Perimeter = x + y + z
计算三角形周长的程序:
示例
#include <iostream>
using namespace std;
int calcPerimeter(int x, int y, int z ){
int perimeter = x + y + z;
return perimeter;
}
int main(){
int x = 5, y = 7, z = 8;
cout<<"The side of the triangle are \n";
cout<<"X = "<<x<<"\tY = "<<y<<"\tZ = "<<z<<endl;
cout<<"The perimeter of the triangle is "<<calcPerimeter(x, y, z);
return 0;
}输出
三角形的边长为
X = 5 Y = 7 Z = 8 The perimeter of the triangle is 20
不同类型三角形的周长:
在数学中,有不同类型的三角形,它们具有一些特殊的性质。虽然周长的基本公式保持不变,但所有类型的三角形都有特定的公式。让我们看看每一个。
等边三角形
这是一种特殊的三角形,其中所有边和角都相等。

Perimeter = 3*a
计算等边三角形面积的程序:
示例
#include <iostream>
using namespace std;
int calcPerimeter(int a){
int perimeter = 3*a;
return perimeter;
}
int main(){
int a = 5;
cout<<"The side of the equilateral triangle are \n";
cout<<"a = "<<a<<endl;
cout<<"The perimeter of the triangle is "<<calcPerimeter(a);
return 0;
}输出
等边三角形的边长为
a = 5 The perimeter of the triangle is 15
等腰三角形
这是一种特殊的三角形,其中两条边相等,第三条边的长度不同。

Perimeter = 2*X + Y
计算等腰三角形周长的程序:
示例
#include <iostream>
using namespace std;
int calcPerimeter(int x, int y){
int perimeter = 2*x + y;
return perimeter;
}
int main(){
int x = 5, y = 8;
cout<<"The side of the Isosceles triangle are \n";
cout<<"X = "<<x<<"\tY = "<<y<<endl;
cout<<"The perimeter of the triangle is "<<calcPerimeter(x, y);
return 0;
}输出
等腰三角形的边长为
X = 5 Y = 8 The perimeter of the triangle is 18
不等边三角形
这是一个三条边都不相同的三角形。

周长 = x + y + z
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP