ADA Program to find the difference of two integer number
Program
With Gnat.IO; use Gnat.IO;
procedure subtwointeger is
a : Integer;
b : Integer;
diff : Integer;
begin
Put ("Enter value of a: ");
Get (a);
Put ("Enter value of b: ");
Get (b);
diff := a - b;
Put_Line ("Difference = " & integer'image(diff));
end;
This Ada program reads two integer numbers from the user, calculates their difference, and displays the result.
-
With Gnat.IO; use Gnat.IO;- Imports the
Gnat.IOpackage for input and output functions. use Gnat.IO;allows direct use of procedures likePut,Put_Line, andGet.
- Imports the
-
procedure subtwointeger is- Defines the procedure
subtwointeger, which is the main program.
- Defines the procedure
-
Variable Declarations:
a : Integer; b : Integer; diff : Integer;- Declares three integer variables:
a→ First numberb→ Second numberdiff→ Stores the difference betweenaandb
- Declares three integer variables:
-
begin- Marks the beginning of the executable code.
-
Taking User Input:
Put ("Enter value of a: "); Get (a); Put ("Enter value of b: "); Get (b);- Prompts the user to enter two integer values.
- Uses
Get(a);andGet(b);to store values inaandb.
-
Calculating Difference:
diff := a - b;- Subtracts
bfromaand stores the result indiff.
- Subtracts
-
Displaying the Result:
Put_Line ("Difference = " & integer'image(diff));integer'image(diff)converts the integerdiffinto a string.Put_Lineprints the result to the console.
-
end;- Marks the end of the program.
Key Features:
- Uses
Gnat.IOfor input and output operations. - Takes two integer inputs and computes their difference.
- Displays the result using
integer'image(diff)for correct formatting.
Output
$ gnat make subtwointeger.adb
gcc -c subtwointeger.adb
gnatbind -x subtwointeger.ali
gnatlink subtwointeger.ali
$ ./subtwointeger
Enter value of a: 76
Enter value of b: 13
Difference = 63