Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

truth or not

program truthOrNot;

uses
  sysutils;

var
  gateInput : string;
  A, B, C : integer;

begin

  writeln('Input Gate');
  readln(gateInput);
  UpperCase(gateInput);

  writeln('|    A    |    B    |    C    |');
  writeln('-------------------------------');

  for A := 0 to 1 do
  begin
    for B:= 0 to 1 do
    begin
        if gateInput = 'AND' then
        begin
          if (A = 1) AND (B = 1) then
          begin
            C := 1;
          end
          else
          begin
            C := 0;
          end;
        end
        else if gateInput = 'OR' then
        begin
          if ((A = 1) AND (B = 1)) OR (A = 1) OR (B = 1) then
          begin
            C := 1;
          end
          else
          begin
            C := 0;
          end;
        end
        else if gateInput = 'NOT' then
        begin
          if ((A = 1) AND (B = 1)) OR (A = 1) OR (B = 1) then
          begin
            C := 1;
          end
          else
          begin
            C := 0;
          end;
        end;

      writeln('|    '+IntToStr(A)+'    '+'|    '+IntToStr(B)+'    '+'|    '+IntToStr(C)+'    |');
      writeln('-------------------------------');

    end;
  end;

readln();

end.

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.