Добрый день! К сожалению я не работаю с C++, но если это то вот эта задача в Pascal VAR a,b,c,d:REAL; PROCEDURE Print_S(x,y,z:REAL); VAR p,S:REAL; begin If ((x+y)>z) and ((x+z)>y) and ((y+z)>x) then begin p:=x+y+z; S:=SQRT(p*(p-x)*(p-y)*(p-z)); WriteLn('S= ',S); end else Writeln('Треугольник не существует!'); end; BEGIN Write('a= '); ReadLn(a); Write('b= '); ReadLn(b); Write('c= '); ReadLn(c); Write('d= '); ReadLn(d); WriteLn; WriteLn('Стороны ',a,'; ',b,'; ',c); Print_S(a,b,c); WriteLn; WriteLn('Стороны ',a,'; ',b,'; ',d); Print_S(a,b,d); WriteLn; WriteLn('Стороны ',a,'; ',c,'; ',d); Print_S(a,c,d); WriteLn; WriteLn('Стороны ',b,'; ',c,'; ',d); Print_S(b,c,d); END.
void TriangleArea(double a, double b, double c) { double p = (a + b + c) / 2; double ss = p * (p - a) * (p - b) * (p - c); // Using Heron's formula if (ss > 0) cout << "Area of triangle = " << sqrt(ss); else cout << "The three sides will not form a triangle."; }
cout << "\n\nThree side lengths to a triangle (a, b, c):\n"; TriangleArea(a, b, c); cout << "\n\nThree side lengths to a triangle (a, b, d):\n"; TriangleArea(a, b, d); cout << "\n\nThree side lengths to a triangle (b, c, d):\n"; TriangleArea(b, c, d); cout << "\n\nThree side lengths to a triangle (a, c, d):\n"; TriangleArea(a, c, d); cout << "\n\n"; }
const n = 16;
var a: array [1..n] of integer;
i, s : integer;
begin
writeln ('Массив: ');
for i:=1 to n do
begin
a[i]:= random(15);
write(a[i], ' ');
end;
writeln;
s:=0;
for i:=1 to 5 do s:=s + a[i];
writeln('Сумма = ', s);
end.
Пример:
Массив:
4 1 6 1 4 9 9 4 3 6 14 0 14 4 13 11
Сумма = 16