戦闘機開発 Adaの定数と変数、四則演算

--定数
--変数
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;

procedure MyApp is
 x: Integer;
 y: constant Integer := 3;
begin
  x := 5;
  put(x);
  new_line;
  x := 10;
  put(x, 5);
  new_line;
  put(y);
  new_line;
end MyApp;

四則演算

--定数
--変数
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;

procedure MyApp is
 x: Integer;
begin
 put("your number? ");
 get(x);

 put(x + 3);
 new_line;
 put(x - 3);
 new_line;
 put(x / 3);
 new_line;
 put(x rem 3);
 new_line;
 put(x * 3);
 new_line;
 put(x ** 3);
 new_line;
end MyApp;

25を入力してみます。

[vagrant@localhost ada_lessons]$ gnatmake myapp.adb
gcc -c myapp.adb
gnatbind -x myapp.ali
gnatlink myapp.ali
[vagrant@localhost ada_lessons]$ ./myapp
your number? 25
         28
         22
          8
          1
         75
      15625