一道C++的编程题

来源:百度知道 编辑:UC知道 时间:2024/05/24 22:39:00
一个三角形3条边分别a,b,c,利用公式sqrt(s(s-a)*(s-b)*(s-c))求三角形的面积,其中s=(a+b+c)/2,假定a,b,c的值由键盘输入,求写出编程过程.
很感谢你啊,已经完全通过了,我刚学C++,还有很多都不太懂,你可以留下你QQ号吗,或者你加我的442836615.我会追加你分.

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
cout << "请输入三角形的边长a: ";
unsigned int a;
cin >> a;
cout << "请输入三角形的边长b: ";
unsigned int b;
cin >> b;
cout << "请输入三角形的边长c: ";
unsigned int c;
cin >> c;

unsigned int s = (a + b + c) / 2;

unsigned int area = sqrt(s*(s-a)*(s-b)*(s-c));

cout << "该三角形的面积为: " << area << endl;

}