const N = 10; var a: array [1..N] of integer; i: integer; i1, i2: integer; begin {init random} for i:=1 to N do a[i]:=random(100)-50; write('array: '); for i:=1 to N do write(a[i]:4); writeln; i1 := 0; i2 := 0; i := 1; while (i1 = 0) or (i2 = 0) do begin if a[i] > 0 then begin if i1 = 0 then begin i1 := i; end else begin if i2 = 0 then begin i2 := i; end; end end; inc(i); if (i > N) then begin break; end end; if i1 > 0 then begin writeln('first positive element: a[', i1, '] = ', a[i1]); if i2 > 0 then begin writeln('second positive element: a[', i2, '] = ', a[i2]); end else begin writeln('no second positive element'); end; end else begin writeln('no positive element at all!'); end; end.
вывод
array: 45 -22 -15 32 -9 9 29 3 -26 -49 first positive element: a[1] = 45 second positive element: a[4] = 32
Комментариев нет:
Отправить комментарий