読み込んだ整数値までカウントアップ、0までカウントダウン (for文)
明解C言語 入門編 > 4. プログラムの流れの繰り返し >
読み込んだ整数値までカウントアップ、0までカウントダウン (for文)
Delphi
program Project1;{$APPTYPE CONSOLE}
uses
SysUtils;
var
no, i: Integer;
begin
write('正の整数を入力してください:');
read(no);for i := 0 to no do
begin
writeln(format('%d', [i]));
end;write(#13#10);
for i := no downto 0 do
begin
writeln(format('%d', [i]));
end;
end.
実行結果
S:\>lesson028\project1.exe
正の整数を入力してください:12
0
1
2
3
4
5
6
7
8
9
10
11
1212
11
10
9
8
7
6
5
4
3
2
1
0