ADA Program to find the product of two integer number
Program
With Gnat.IO; use Gnat.IO;
procedure multwointeger is
a : Integer;
b : Integer;
mul : Integer;
begin
Put ("Enter value of a: ");
Get (a);
Put ("Enter value of b: ");
Get (b);
mul := a * b;
Put_Line ("Product = " & integer'image(mul));
end;
This Ada program reads two integer numbers from the user, multiplies them, and displays the result.
-
With Gnat.IO; use Gnat.IO;
- Imports the
Gnat.IO
package for input and output functions. use Gnat.IO;
allows direct use of procedures likePut
,Put_Line
, andGet
.
- Imports the
-
procedure multwointeger is
- Defines the procedure
multwointeger
, which is the main program.
- Defines the procedure
-
Variable Declarations:
a : Integer; b : Integer; mul : Integer;
- Declares three integer variables:
a
→ First numberb
→ Second numbermul
→ Stores the product ofa
andb
- 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 ina
andb
.
-
Calculating Product:
mul := a * b;
- Multiplies
a
andb
and stores the result inmul
.
- Multiplies
-
Displaying the Result:
Put_Line ("Product = " & integer'image(mul));
integer'image(mul)
converts the integermul
into a string.Put_Line
prints the result to the console.
-
end;
- Marks the end of the program.
Key Features:
- Uses
Gnat.IO
for input and output operations. - Takes two integer inputs and computes their product.
- Displays the result using
integer'image(mul)
for correct formatting. - Demonstrates basic arithmetic multiplication in Ada.
Output
$ gnat make multwointeger.adb
gcc -c multwointeger.adb
gnatbind -x multwointeger.ali
gnatlink multwointeger.ali
$ ./multwointeger
Enter value of a: 13
Enter value of b: 65
Product = 845