判断三角形类型 018

本文介绍了一个使用C语言编写的程序,该程序能够根据用户输入的三边长度判断是否可以构成三角形,并进一步判断其类型(等边、等腰、直角或其他),最后计算并输出相应的三角形面积。
int main()
{
	double longs, width, height;
	printf("请输入三条边长度:");
	scanf("%lf %lf %lf", &longs, &width, &height);
	double temp = (longs + width + height) / 2;
	double ret = sqrt(temp*(temp - longs) * (temp - width) * (temp - height));
	if (longs + width > height && longs + height > width && width + height > longs)
	{
		if (longs == width && width == height && height == width)
		{
			printf("等边三角形 面积为:%lf", (longs*height)*0.5);
		}
		else if (longs == width || longs == height || width == height)
		{
			 /*海伦公式:三角形面积S = √[P(P - A)(P - B)(P - C)]
			  其中P = (A + B + C) / 2
			  A、B、C表示三角形的边长,√表示根号,即紧跟后面的括号内的全部数开根号*/
			
			printf("等腰三角形 面积为%lf", ret);
		}
		//直角三角形特征;两边的平方等于第三边的平方、
		else if (longs * longs + width *width == height*height || longs *longs + height*height == width *width 
			|| width * width + height*height == longs*longs)
		{
			
			printf("直角三角形,面积为%lf",ret);
		}
		else
		{
			printf("普通三角形");
		}
		
	}
	else
	{
		printf("\n不能构成三角形");
	}

	system("pause");
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值