読み込んだ整数値を0までカウントダウン (while文)

明解C言語 入門編 > 4. プログラムの流れの繰り返し >

読み込んだ整数値を0までカウントダウン (while文)

Delphi


program Project1;

{$APPTYPE CONSOLE}

uses
SysUtils;
var
no: Integer;
begin
write('正の整数を入力してください:');
read(no);

while (no >= 0) do
begin
writeln(format('%d', [no]));
dec(no);
end;
end.

実行結果

S:\>lesson027\project1.exe
正の整数を入力してください:11
11
10
9
8
7
6
5
4
3
2
1
0

S:\>lesson027\project1.exe
正の整数を入力してください:0
0

S:\>lesson027\project1.exe
正の整数を入力してください:-5