読み込んだ整数値を逆順に表示 (do文)
明解C言語 入門編 > 4. プログラムの流れの繰り返し >
読み込んだ整数値を逆順に表示 (do文)
Delphi
program Project1;{$APPTYPE CONSOLE}
uses
SysUtils;
var
no, dig: Integer;
begin
repeat
write('正の整数を入力してください:');
read(no);if (no < 0) then
writeln(#7'負の数を入力しないでください。')
until no >= 0;write('その数を逆から読むと');
dig := 0;
repeat
write(format('%d', [no mod 10]));
no := no div 10;
inc(dig);
until no <= 0;writeln('です。');
writeln(format('その数は%d桁です。', [dig]));
end.
実行結果
S:\>lesson025\project1.exe
正の整数を入力してください:-17
負の数を入力しないでください。
正の整数を入力してください:1963
その数を逆から読むと3691です。
その数は4桁です。