recursive_write_natural.adb

来自「This contains the following topics and m」· ADB 代码 · 共 21 行

ADB
21
字号
with Ada.Text_IO; use Ada.Text_IO;
procedure Recursive_program is

   procedure Write_Natural (Num : Natural) is
      First_Digit  : Natural; --Unit digit
      Other_Digits : Natural; --All except first digit
   begin
      First_Digit  := Num rem 10; --Split 1234 => 4
      Other_Digits := Num / 10; -- => 123
      if Num >= 10 then --Print other digits
         Write_Natural (Other_Digits); --Recursive call
      end if;
      Put (Character'Val (First_Digit + Character'Pos ('0')));
   end Write_Natural;
begin
   Write_Natural (1234);
   New_Line;
   Write_Natural (12345);
   New_Line;
end Recursive_program;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?