输入一个三角形的3个边长a,b,c,求三角形的面积。

输入一个三角形的3个边长a,b,c,求三角形的面积。
提示:用海伦公式S=sqrt(h*(h-a)(h-b)(h-c)),其中h是半周长,sqrt是平方根函数,在math.h中定义

#include<stdio.h>
#include<math.h> 
int main(){
	double a,b,c,s,h;
	printf("请输入三个数:\n");
	scanf("%lf%lf%lf",&a,&b,&c) ;
	if(a<0||b<0||c<0)
	{
	  printf("无效的输入:\n");
	  return 0;
	}	
	if(a+b>c&&a+c>b&&c+b>a){
		h=(a+b+c)/2;
		s=sqrt(h*(h-a)*(h-b)*(h-c));
		printf("%f\n",s);
	}
	else
	    printf("无效输入:\n");
	return 0;
} 

5.2根据会员等级计算应付金额。

#include<stdio.h>
#include<math.h> 
int main(){
    int c;
    float pay,discount;
    printf("输入客户等级:\n");
	scanf("%d",&c);     //1,2,3分别代表普通,银卡,金卡会员。其他就是非会员。
	printf("输入商品总金额:\n");
	scanf("%f",&pay);
	if(c==1)discount=0.9;
	else if(c==2)discount=0.85;
	else if(c==3)discount=0.8;
	else  discount=1.0;
	pay=pay*discount;
	printf("应付金额:%.2f\n",pay); 
	return 0;
} 
  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值