C++初学者,求教~谢谢各位大神~用海伦公式计算三角形面积的编程
#include<iostream.h>voidmain(){doublea;doubleb;doublec;doublep;cout<<"pleaseinputanum...
#include <iostream.h>
void main()
{
double a;
double b;
double c;
double p;
cout<<"please input a number as one of the lines"<<endl;
cin>>a;
cout<<"please input another one"<<endl;
cin>>b;
cout<<"the last one is required to be larger than "<<b-a<<" smaller than "<<a+b<<endl;
cin>>c;
p=0.5*(a+b+c);
res=p*(p-a)*(p-b)*(p-c);
cout<<"square is "<<res<<endl;
}
运行结果如图……在线等…… 展开
void main()
{
double a;
double b;
double c;
double p;
cout<<"please input a number as one of the lines"<<endl;
cin>>a;
cout<<"please input another one"<<endl;
cin>>b;
cout<<"the last one is required to be larger than "<<b-a<<" smaller than "<<a+b<<endl;
cin>>c;
p=0.5*(a+b+c);
res=p*(p-a)*(p-b)*(p-c);
cout<<"square is "<<res<<endl;
}
运行结果如图……在线等…… 展开
3个回答
展开全部
#include <iostream.h>
#include <math.h> //使用根号函数要用这个头文件
void main()
{
double a;
double b;
double c;
double p;
cout<<"please input a number as one of the lines"<<endl;
cin>>a;
cout<<"please input another one"<<endl;
cin>>b;
cout<<"the last one is required to be larger than "<<b-a<<" smaller than "<<a+b<<endl;
cin>>c;
p=0.5*(a+b+c);
double res=sqrt(p*(p-a)*(p-b)*(p-c)); //注意,要开根号的...
cout<<"square is "<<res<<endl;
}
#include <math.h> //使用根号函数要用这个头文件
void main()
{
double a;
double b;
double c;
double p;
cout<<"please input a number as one of the lines"<<endl;
cin>>a;
cout<<"please input another one"<<endl;
cin>>b;
cout<<"the last one is required to be larger than "<<b-a<<" smaller than "<<a+b<<endl;
cin>>c;
p=0.5*(a+b+c);
double res=sqrt(p*(p-a)*(p-b)*(p-c)); //注意,要开根号的...
cout<<"square is "<<res<<endl;
}
更多追问追答
追问
结果还是不行啊……
追答
用我的代码应该是没问题的,我运行过了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询