Составьте алгоритм упорядочения значений трех переменных по возрастанию, т. е. при любых исходных значениях А, B, С.

Информатика 9 класс Семакин ФГОС

§ 12 Алгоритмы с ветвящейся структурой ГДЗ по Информатике 9 класс. Семакин


9. Составьте алгоритм упорядочения значений трех переменных по возрастанию, т. е. при любых исходных значениях А, B, С отсортируйте их так, чтобы стало: А ≤ В ≤ С. Проверьте алгоритм трассировкой при разных вариантах значений исходных данных.

Ответ

Алг СОРТИРОВКА-3                                                         Program SORT_3;

вещ А, В, С, X                                                                      var A,B,C,X: real;

нач                                                                                                         begin

ввод А, В, С                                                                                          readln (А, В, С);

если А > В                                                                                            if A > В

то                                                                                                            then begin

X := А;                                                                                   X := А;

А := В;                                                                                   А := В;

В := X                                                                                     В := X

kb                                                                                                            end;

если В > С                                                                                             if В > С

то then                                                                                   begin

X := В;                                                                                    X := В;

В := С;                                                                                    В := С;

С := X                                                                                     С := X

kb                                                                                                            end;

если А > В                                                                                            if A > В

то                                                                                                            then begin

X := А;                                                                                   X := А;

А := В;                                                                                   А := В;

В := X                                                                                     В := X

kb                                                                                                            end;

вывод А,В,С                                                                         write(А,В,С)

кон                                                                                                         end.


Понравилась статья? Поделиться с друзьями: