Задача 8 Урок 9
Primary tabs
Пользователь вводит три числа, найдите из них максимальное.
Решите тремя способами:
1. С использованием логической операции and.
2. С вложенными блоками (без and, все операторы if должны быть в полной форме).
3. Без вложенных блоков (без and) -- запомнив максимум из первых двух чисел в специальной переменной.
var A,B,C,max:integer; begin writeln('Input first number'); readln(A); writeln('Input second number'); readln(B); writeln('Input third number'); readln(C); // 1 if ((A >= B) and (A >= C)) then writeln('Max number is ', A) else if ((B >= A) and (B >= C)) then writeln('Max number is ', B) else if ((C >= B) and (C >= A)) then writeln('Max number is ', C); // 2 if (A > B) then if (A > C) then writeln('Max number is ', A) else writeln('Max number is ', C) else if (B > A) then if (B > C) then writeln('Max number is ', B) else writeln('Max number is ', C) else writeln('Numbers are equal = ', A); // 3 if (A >= B) then max:=A; if (B >= A) then max:=B; if (C > max) then max:=C; writeln('Max number is ', max); readln(); end.
- Log in to post comments
- 62 reads