読み込んだ3つの整数値の最大値を返す関数
明解C言語 入門編 > 6. 関数 >
読み込んだ3つの整数値の最大値を返す関数
Delphi
program Project1;{$APPTYPE CONSOLE}
uses
SysUtils;function max3(x: Integer; y: Integer; z: Integer): Integer;
begin
result := x;if y > result then result := y;
if z > result then result := z;
end;var
n1, n2, n3: Integer;
begin
writeln('3つの整数を入力してください。');write('整数1:');
read(n1);write('整数2:');
read(n2);write('整数3:');
read(n3);writeln(format('最も大きい値は%dです。', [max3(n1, n2, n3)]));
end.
実行結果
S:\>lesson044\project1.exe
3つの整数を入力してください。
整数1:83
整数2:45
整数3:25
最も大きい値は83です。