EXAMPLE:
Input:
n = 10
v_min = -5
v_max = 10
Original vector:
7 3 1 -5 -2 5 2 0 10 9
Imprint
second_otr = -2 n_second_otr = 5
predp_pol = 10 n_predp_pol = 9
Output vector:
7 3 1 -5 10 5 2 0 -2 9
Itx programm:
Var V:array[1..100] of integer;
n,vmin,vmax,i,j,p,k,t,buf:integer;
Begin
write('Введите n: ');readln(n);
write('Введите vmin: ');readln(vmin);
write('Введите vmax: ');readln(vmax);
k:=0;t:=0;
writeln('Исходный');
For i:=1 to n do
Begin
V[i]:=random(31)-15;
write(V[i]:4);
if (V[i]<0)and(t=0)and(k=1) then t:=i;//второй отрицательный
if (V[i]<0) then k:=1;
End;
j:=0;p:=0;
For i:=n downto 1 do
Begin
if (V[i]>0)and(p=0)and(j=1) then p:=i;//предпоследний положительный
if (V[i]>0) then j:=1;
End;
writeln;
if (t>0)and(p>0) then
Begin
writeln('Второй отрицательный = ',V[t],' он находится V[',t,']');
writeln('Предпоследний положительный = ',V[p],' он находится V[',p,']');
buf:=V[t];
V[t]:=V[p];
V[p]:=buf;
writeln('Преобразованный');
For i:=1 to n do
write(V[i]:4);
End
else writeln('Нету второго отрицательного или предпоследнего положительного');
readln;
End.
But I can not understand how it works here, this part of the program and what all the variables k and t
k:=0;t:=0;
writeln('Исходный');
For i:=1 to n do
Begin
V[i]:=random(31)-15;
write(V[i]:4);
if (V[i]<0)and(t=0)and(k=1) then t:=i;//второй отрицательный
if (V[i]<0) then k:=1;
End;

New Topic/Question
Reply




MultiQuote


|