• Дан целочисленный массив А. Удалить из массива все одинаковые элементы.В чем моя ошибка?
    program hgfd1;
    const n=5;
    var a:array[1..n] of integer;
    i,c:integer;
    begin
    randomize;
    for i:=1 to n do
    begin
    a[i]:=random(8)+0;
    writeln('a[',i,']=',a[i]);
    end;
    for i:=2 to n do
    for c:=i-1to 1 do
    if a[i]=a[c] then
    a[i]:=a[i+1];
    for i:=1 to n do
    writeln('a[',i,']=',a[i]);
    end.

Ответы 1

  • //Как-то громоздко получилось, но я так вижу. Эх, выходные.const n=5;var a:array[1..n] of integer;b:array[0..8] of integer;ar:array[1..n] of integer;i,c,j:integer;beginrandomize;writeln('Array:');for i:=1 to n dobegina[i]:=random(8);write(a[i]:4);end;for i:=1 to n do begin;  for j:=0 to 8 do    if a[i]=j then inc(b[j]); end;for i:=1 to n do begin;  for j:=0 to 8 do   if (b[j]>1) and (a[i]=j) then a[i]:=9; if a[i]<>9 then  begin;   inc(c);   ar[c]:=a[i];  end; end; writeln; for i:=0 to 8 do writeln(i,'=',b[i]);writeln;writeln('Final array:');for i:=1 to n doif a[i]=9 then a[i]:=0;for i:=1 to c dobegin; a[i]:=ar[i]; write(a[i]:4);end;end.
    • Автор:

      pookie63
    • 6 лет назад
    • 0
  • Добавить свой ответ

Войти через Google

или

Забыли пароль?

У меня нет аккаунта, я хочу Зарегистрироваться

How much to ban the user?
1 hour 1 day 100 years