Advertisement
CrazyDiver

Cycles/Divisibility[H]

Dec 12th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.23 KB | None | 0 0
  1. procedure VvodCh(var a, b: longint);
  2. begin
  3.   readln(a, b);  //read 2 nums
  4. end;
  5.  
  6. function CheckDivOnDshcs(inp: longint): boolean;
  7. var
  8.   cop_inp: longint;
  9.   res: boolean;
  10. begin
  11.   cop_inp := inp;  //copy inputted val
  12.   res := true;  //assign to the logic var true value
  13.   while (cop_inp > 0) and res do  //repeat cycle if copied val more than 0 and res is 1
  14.     begin
  15.       if (cop_inp mod 10) <> 0 then  //if copied num isnt ends wth 0 then
  16.         res := (inp mod (cop_inp mod 10)) = 0  //res is 1 if division and getting remainder inputted num on last discharge of copied val isnt 0
  17.       else  //else
  18.         res := false;  //logic var eq 0
  19.       cop_inp := cop_inp div 10;  //cut las discharge of copied num
  20.     end;
  21.   CheckDivOnDshcs := res;  //assign to the res of func last vaalue of logic var
  22. end;
  23.  
  24. procedure WriteNumsAccordLogicF(a, b: longint);
  25. var
  26.   i: longint;
  27. begin
  28.   for i := a to b do  //iterate all nums in range from a to b
  29.     if CheckDivOnDshcs(i) then  //if num approach all logic func demands then
  30.       write(' ', i);  //write space and this num
  31. end;
  32.  
  33. var
  34.   a, b: longint;
  35.  
  36. begin
  37.   VvodCh(a, b);  //read 2 nums
  38.   WriteNumsAccordLogicF(a, b);  //write nums in range if then approach logic func demands
  39. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement