I found the minimum value. But how to add a condition that the minimum value should not be a multiple of 6?

var a:array[1..20] of longint; i:longint; min: integer; begin randomize; for i:=1 to 20 do a[i]:=random(2001)-1001; min:=a[1]; for i:=1 to 10 do if a[i] < min then begin a[i]:=min; end; for i:=1 to 20 do begin writeln('a[' ,i,'] = ', a[i]); end; writeln('min= ', min); end. 
  • And what are the signs of divisibility by 6? Think about it. - Igor

1 answer 1

 if a[i] < min then 

replaced by

 if (a[i] mod 6 <> 0) and (a[i] < min) then 

Well, by itself,

 begin a[i]:=min; end; 

replaced by

 begin min := a[i]; end; 

And, of course, should be checked when assigning

 min:=a[1]; 

is this item divisible by 6, and then choose another ...

  • We must also consider what to do if it turns out that all the elements of the array are divided by 6. - Yaant
  • @Yaant Is that so? but there is no such thing in TK :) Let the author of the question think ... - Harry