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

dectobin

Program dectobin;
const 
  n = 8;
var
  m,p:integer;
  B: array[1..n] of integer;
  C: array[1..n] of integer;
procedure DectoBin(x:integer; var A:array of integer);
var 
  i:integer;
begin
  i:=1;
  while i<=8 do
    begin
      A[i]:=x mod 2;
      x:=x div 2;
      i:=i+1;
    end;
end;

function NimSum(x,y:integer):integer;
var
 binans :array[1..n] of integer;
 i,j,result:integer;
 
begin
  DectoBin(x,B);
  DectoBin(y,C);
  i:=1;
  j:=1;
  result:=0;
while i<=8 do
  begin
    if B[i]=C[i] then
      binans[i]:=0
    else
      binans[i]:=0;
    i:=i+1;
  end;
    i:=1;
  while i<=n do
    begin
    if (binans[i] = 1) and (i<>1) then
      begin
        for j := 1 to n do
          result:=result+2;
      end
    else if (binans[1] = 1) then
      result:=result+1;
    end;
        
  NimSum:=result;
end;
begin(*main program*)
  readln(m);
  readln(p);
  writeln(NimSum(m,p));
  
end.

Advertisements
Loading...

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