How to resolve the algorithm Arithmetic/Integer step by step in the Ada programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Arithmetic/Integer step by step in the Ada programming language
Table of Contents
Problem Statement
Get two integers from the user, and then (for those two integers), display their:
Don't include error handling. For quotient, indicate how it rounds (e.g. towards zero, towards negative infinity, etc.). For remainder, indicate whether its sign matches the sign of the first operand or of the second operand, if they are different.
Bonus: Include an example of the integer divmod
operator. For example: as in #Haskell, #Python and #ALGOL 68
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Arithmetic/Integer step by step in the Ada programming language
Source code in the ada programming language
with Ada.Text_Io;
with Ada.Integer_Text_IO;
procedure Integer_Arithmetic is
use Ada.Text_IO;
use Ada.Integer_Text_Io;
A, B : Integer;
begin
Get(A);
Get(B);
Put_Line("a+b = " & Integer'Image(A + B));
Put_Line("a-b = " & Integer'Image(A - B));
Put_Line("a*b = " & Integer'Image(A * B));
Put_Line("a/b = " & Integer'Image(A / B));
Put_Line("a mod b = " & Integer'Image(A mod B)); -- Sign matches B
Put_Line("remainder of a/b = " & Integer'Image(A rem B)); -- Sign matches A
Put_Line("a**b = " & Integer'Image(A ** B));
end Integer_Arithmetic;
You may also check:How to resolve the algorithm Super-d numbers step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Currying step by step in the GDScript programming language
You may also check:How to resolve the algorithm Abbreviations, simple step by step in the Haskell programming language
You may also check:How to resolve the algorithm Empty program step by step in the EDSAC order code programming language
You may also check:How to resolve the algorithm Yahoo! search interface step by step in the Go programming language