从键盘上输入3个数,分别设为三角形的3条边,然后求其面积
#include "stdio.h"
#include "conio.h"
#include <math.h>
main(){
float a,b,c;
float area;
float s;
scanf("%f,%f,%f",&a,&b,&c);
if((a+b)<c){
printf("erro");
}else if((a-b)>c){
printf("erro");
}else{
s=1.0/2*(a+b+c);
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("%f",area);
}
getch();
}
这个程序花了我好长时间啊
知道sqrt是求开方
但是,要注意的细节有好多
首先 调用scanf函数的时候,输入的格式,得要和定义的类型一致,不然的话会有偏差
还有就是一定要导入包 math,,因为调用了sqrt函数,
不然的结果保准会出来什么