読み込んだ月の季節を表示 (論理演算子)

明解C言語 入門編 > 3. プログラムの流れと分岐 >

読み込んだ月の季節を表示 (論理演算子)

Delphi


program Project1;

{$APPTYPE CONSOLE}

uses
SysUtils;
var
month: Integer;
begin
write('何月ですか:');
read(month);

if (3 <= month) and (month <= 5) then
writeln('春です。')
else if (6 <= month) and (month <= 8) then
writeln('夏です。')
else if (9 <= month) and (month <= 11) then
writeln('秋です。')
else if (month = 1) or (month = 2) or (month = 12) then
writeln('冬です。')
else
writeln('そんな月はありませんよ!!');
end.

実行結果

S:\>lesson022\project1.exe
何月ですか:5
春です。

S:\>lesson022\project1.exe
何月ですか:8
夏です。