How to resolve the algorithm Logical operations step by step in the Modula-2 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Logical operations step by step in the Modula-2 programming language

Table of Contents

Problem Statement

Write a function that takes two logical (boolean) values, and outputs the result of "and" and "or" on both arguments as well as "not" on the first arguments. If the programming language doesn't provide a separate type for logical values, use the type most commonly used for that purpose. If the language supports additional logical operations on booleans such as XOR, list them as well.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Logical operations step by step in the Modula-2 programming language

Source code in the modula-2 programming language

MODULE LogicalOps;
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;

PROCEDURE Print(a,b : BOOLEAN);
VAR buf : ARRAY[0..31] OF CHAR;
BEGIN
    FormatString("a and b is %b\n", buf, a AND b);
    WriteString(buf);
    FormatString("a or b is %b\n", buf, a OR b);
    WriteString(buf);
    FormatString("not a is %b\n", buf, NOT a);
    WriteString(buf);
    WriteLn
END Print;

BEGIN
    Print(FALSE, FALSE);
    Print(FALSE, TRUE);
    Print(TRUE, TRUE);
    Print(TRUE, FALSE);

    ReadChar
END LogicalOps.


  

You may also check:How to resolve the algorithm Mertens function step by step in the Fortran programming language
You may also check:How to resolve the algorithm Conjugate transpose step by step in the Maple programming language
You may also check:How to resolve the algorithm Catamorphism step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Hostname step by step in the J programming language
You may also check:How to resolve the algorithm Check that file exists step by step in the RLaB programming language