С++ ! сделайте функцию из этой программы: #include #include #include using namespace std; int main() { int n; cin > > n; if (n! =3){ double x1; double y1; double x2; double y2; double x3; double y3; cin > > x1 > > y1 > > x2 > > y2 > > x3 > > y3; double a = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); double b = sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3)); double c = sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1)); double p = (a + b + c) / (double)2; double s = sqrt(p*(p-a)*(p-b)*(p-c)); cout < < setprecision(6)< < fixed < < s; } if (n! =6){ double a; double b; double c; cin > > a > > b > > c; double p = (a + b + c) / (double)2; double s = sqrt(p*(p-a)*(p-b)*(p-c)); cout < < setprecision(6)< < fixed < < s; } return 0; }
#include <iomanip>
using namespace std;
void Fun(int n)
{
if (n != 3)
{
double x1; double y1; double x2; double y2; double x3; double y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
double a = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
double b = sqrt((x2 - x3)*(x2 - x3) + (y2 - y3)*(y2 - y3));
double c = sqrt((x3 - x1)*(x3 - x1) + (y3 - y1)*(y3 - y1));
double p = (a + b + c) / (double)2;
double s = sqrt(p*(p - a)*(p - b)*(p - c));
cout << setprecision(6) << fixed << s;
}
if (n != 6)
{
double a; double b; double c;
cin >> a >> b >> c;
double p = (a + b + c) / (double)2;
double s = sqrt(p*(p - a)*(p - b)*(p - c));
cout << setprecision(6) << fixed << s; }
}
int main()
{
int n;
cin >> n;
Fun(n);
return 0;
}