P5717 【深基3.习8】三角形分类

在这里插入图片描述

1.思路

最重要的一点是:两边之后大于第三边才是三角形,这是必不可少的!
然后可以考虑用函数的形式来判断每一种情况。

2.源码

//1.两边之和小于第三边 输出  Not triangle
//2. a^2+b^2==c^2      输出  Right triangle
//3. a^2+b^2 > c^2	   输出  Acute triangle
//4. a^2+b^2 < c^2	   输出  Obtuse triangle
//5. a=b&&a+b > c      输出  Isosceles triangle
//6. a=b=c             输出  Equilateral triangle



#include<bits/stdc++.h>

using namespace std;

void triangle1(int a,int b,int c){    
	if(a+b<=c){
		cout<<"Not triangle"<<endl;
	}
}

void triangle2(int a,int b,int c){
	if(a*a+b*b==c*c  &&a+b>c){
		cout<<"Right triangle"<<endl;
	}
}

void triangle3(int a,int b,int c){
	if(a*a+b*b>c*c &&a+b>c){
		cout<<"Acute triangle"<<endl;
	}
}

void triangle4(int a,int b,int c){
	if(a*a+b*b<c*c  &&a+b>c){
		cout<<"Obtuse triangle"<<endl;
	}
}

void triangle5(int a,int b,int c){
	if(  (a==b&&a+b > c )  ||  (b==c&&a+b >c) ){
		cout<<"Isosceles triangle"<<endl;
	}
}

void triangle6(int a,int b,int c){
	if(a==b&& b==c   &&a+b>c){
		cout<<"Equilateral triangle"<<endl;
	}
}

int main(){
	int z[3];
	for(int i=0;i<3;i++)
		cin>>z[i];
	sort(z,z+3);
	int a=z[0],b=z[1],c=z[2];
	triangle1(a,b,c);
	triangle2(a,b,c);
	triangle3(a,b,c);
	triangle4(a,b,c);
	triangle5(a,b,c);
	triangle6(a,b,c);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ღ江晚吟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值