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.

  1. With Gnat.IO; use Gnat.IO;

    • Imports the Gnat.IO package for input and output functions.
    • use Gnat.IO; allows direct use of procedures like Put, Put_Line, and Get.
  2. procedure multwointeger is

    • Defines the procedure multwointeger, which is the main program.
  3. Variable Declarations:

    a : Integer;
    b : Integer;
    mul : Integer;
    
    • Declares three integer variables:
      • a → First number
      • b → Second number
      • mul → Stores the product of a and b
  4. begin

    • Marks the beginning of the executable code.
  5. 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); and Get(b); to store values in a and b.
  6. Calculating Product:

    mul := a * b;
    
    • Multiplies a and b and stores the result in mul.
  7. Displaying the Result:

    Put_Line ("Product = " & integer'image(mul));
    
    • integer'image(mul) converts the integer mul into a string.
    • Put_Line prints the result to the console.
  8. 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