C 程序,用于检查三角形是否为等边三角形、等腰三角形或不等边三角形
三角形由三边和三个角组成。根据这三条边,三角形有三种类型 −
- 等边三角形:所有三条边都相等。
- 等腰三角形:所有两条边都相等。
- 不等边三角形:没有边相等。
编写相应程序,请遵循以下算法。
算法
Step 1: Declare three sides of triangle. Step 2: Enter three sides at run time. Step 3: If side1 == side2 && side2 == side3 Go to step 6 Step 4: If side1 == side2 || side2 == side3 || side3 == side1 Go to Step 7 Step 5: Else Go to step 8 Step 6: Print the triangle is equilateral. Step 7: Print the triangle is isosceles. Step 8: Print the triangle is scalene.
程序
以下是用于检查三角形是否为等边、等腰或不等边的 C 程序 −
#include<stdio.h> int main(){ int side1, side2, side3; printf("Enter sides of triangle:"); scanf("%d%d%d",&side1,&side2,&side3); if(side1 == side2 && side2 == side3) printf("The Given Triangle is equilateral
"); else if(side1 == side2 || side2 == side3 || side3 == side1) printf("The given Triangle is isosceles
"); else printf("The given Triangle is scalene
"); return 0; }
输出
让我们编译并运行上述程序,该程序将生成以下结果 −
Run1: Enter sides of triangle:3 4 6 The given Triangle is scalene Run2 : Enter sides of triangle:2 2 5 The given Triangle is isosceles Run 3: Enter sides of triangle:5 5 5 The Given Triangle is equilateral
广告