编写一个求三角形面积的函数
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/13 17:51:50
运用海伦公式dimPaslong,Saslongifa+b>cthenifb+c>athenifa+c>bthenp=(a+b+c)/2S=sqr(p*(p-a)*(p-b)*(p-c))endife
#include#includefloatarea(float,float,float);voidmain(){\x09floata,b,c,result;\x09printf("输入三角形的三边:\
#include#includemain{inta,b,c;intp,s;scanf("%d%d%d",&a,&b,&c);p=(a+b+c)/2;if(a+b>c&&a+c>b&&b+c>a){s=
#includeclassangle{private:floatx,y,z;public:angle();voidthreeb(floata,floatb,floatc);friendvoidcoma
includeincludeddoublefun(inta,intb,intc){intp;p=(a+b+c)/2;returnsqrt(p*(p-a)*(p-b)*(p-c));}再问:ok再问:
classTriangle{private:\x05doublea;\x05doubleb;\x05doublec;public:\x05Triangle():a(0),b(0),c(0){}\x05
#include#includeusingnamespacestd;intmain(){floata;floatb;floatc;floats;floatp;coutb>>c;p=(a+b
#include#include#includeusingnamespacestd;classbase{public:virtualvoiddisp()=0;};classtriangle:publi
function [ s ] = solve_area( a,b,c ) p=(a+b+c)./2;&nbs
假设知道三角形的三边长为a,b,c.程序如下:#include#includedoublearea(doublea,doubleb,doublec){doublearea=0,s=0;s=(a+b+c
三角形面积可以用海伦公式
错误提示是什么?此句应该为scanf("%d,%d",&a,&h);
用海伦公式比较简单.不知道你要用什么语言编写?我简单写一下C语言的:doublesabc(doublea,doubleb,doublec){doublep,s;p=(a+b+c)/2;s=squrt(
p=1/4*(2*x*z+y*y-x*x-z*z);应该改为p=1.0/4*(2*x*z+y*y-x*x-z*z);或者p=1/4.0*(2*x*z+y*y-x*x-z*z);原因是:当进行运算时,1
voids(folata,folatb,folatc){folatp;p=(a+b+c)/2;S=√[p(p-a)(p-b)(p-c)];returns;}
#include#include#definePI3.14159usingnamespacestd;classShape{public:virtualdoublegetArea()=0;protect
//使用海伦公式#include/*ForIO*/#include/*Forsqrt()*/intmain(void){doublea,b,c,p,s;printf("请输入a,b和c:");scan
functionfun(d,h){if(d
#include#includeusingnamespacestd;classSanJiaoXing{private:doublea,b,c;public:doubleArea();SanJiaoXi
利用海伦公式:S=(p(p-a)(p-b)(p-c))^(1/2);S为三角形面积,a,b,c为三角形三边长,p为三角形半周长(p=(a+b+c)*(1/2))(p(p-a)(p-b)(p-c))^(