0

Задача звучит так:

Если сумма трёх действительных чисел x,y,z меньше 1 то наименьшее из трёх чисел заменить полусуммой двух других, в противном случае заменить меньшее из x и y полусуммой оставшихся значений.

Полусумма должна быть в x, а у меня показывает в y. Как исправить?
Вот, на всякий случай код программы:

procedure TForm3.Button1Click(Sender: TObject);
var
  x, y, z: real;
  C1,C2,C3:integer;
begin
Val(Edit1.Text,x,C1);
Val(Edit2.Text,z,C2);
Val(Edit3.Text,z,C3);
If (C1 = 0) and (C2 = 0) and (C3 = 0) Then
begin
  if x + y + z < 1
  then
  begin
    if int(x) < int(y) then
    begin
      if x < z then
        x := (y + z) / 2
      else
        z := (x + y) / 2;
    end
    else
    begin
      if y < z then
        y := (x + z) / 2
      else
        z := (x + y) / 2;
    end;
  end
  else
  begin
    if x < y then
      x := (y + z) / 2
    else
      y := (x + z) / 2;
  end;

  Memo2.Text:='X=' + floattostr(x) + ' Y=' + floattostr(y) + ' Z=' + floattostr(z);
   end
  else
  Memo2.Text:='Введите числа';
end;
2

1 ответ 1

-1

Вроде работает: https://ideone.com/InG8As

program ideone;
var
  x, y, z, s: double;
  p: ^double;
begin
  readln(x, y, z);

  s := x + y + z;

  if x < y then p := @x else p := @y;
  if (s < 1) and (z < p^) then p := @z;

  p^ := (s - p^) / 2;

  writeln(x:7:4, y:7:4, z:7:4);
end.
4 2 1
 4.0000 2.5000 1.0000
0.5 0.25 0.125
 0.5000 0.2500 0.3750

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.