Задача на Паскале Массивы
задание:
В целочисленном векторе vectorn переместить в начало все нулевые элементы, за ними – все отрицательные элементы в порядке их следования, а за ними – все положительные элементы в порядке их следования. Программа рабочая но нужно избавиться от masVih, т.е. использовать только один массив - кто-нибудь может помочь? Uses Crt; Var i,j:Byte; mas:array[1..10] of integer; masVih:array[1..10] of integer; min,max,n:integer; Begin write ('n = '); readln (n); Write('min = '); ReadLn(min); Write('max = '); ReadLn(max); WriteLn; WriteLn('Ishodny vector:'); Randomize; for i:=1 to n do begin mas[i]:=random(max-min+1)+min; write(mas[i]); write(' '); end; WriteLn; WriteLn('Vihodnoy vector:'); j:=1; for i:=1 to n do begin if (mas[i]=0)then begin masVih[j]:=mas[i]; j:=j+1; end; end; for i:=1 to n do begin if (mas[i]<0)then begin masVih[j]:=mas[i]; j:=j+1; end; end; for i:=1 to n do begin if (mas[i]>0)then begin masVih[j]:=mas[i]; j:=j+1; end; end; for i:=1 to n do begin write(masVih[i]); write(' '); end; readln; End. |
Часовой пояс GMT +4, время: 00:39. |
Powered by vBulletin® Version 4.5.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.