Помощь - Поиск - Пользователи - Календарь
Полная версия: Матрица
Форум «Всё о Паскале» > Pascal, Object Pascal > Задачи
Lenka
Никак не могу для while и repeat сделать эту задачу
Код
program Lab3; uses crt;
label vvod;
var tab:array [1..5,1..5] of integer;
   pob:array [1..5] of integer;
   por:array [1..5] of integer;
   a,b,chislo:integer;
BEGIN

clrscr;

for a:=1 to 5 do
for b:=1 to 5 do
   begin
   if a=b then tab[a,b]:=0
   else vvod:
       begin
       write('Vvedite znachenie yacheyki (',a,',',b,'): ');
       readln(tab[a,b]);
       if (tab[a,b]<0) or (tab[a,b]>2) then
           begin
           writeln('Nevernoe znachenie. Povtorite eshe raz.');
           goto vvod;
           end;
       end;
   end;

writeln;
writeln('Poluchennaya matritsa:');
for a:=1 to 5 do
writeln(tab[a,1],' ',tab[a,2],' ',tab[a,3],' ',tab[a,4],' ',tab[a,5]);

for a:=1 to 5 do
   begin
   pob[a]:=0; por[a]:=0;
   for b:=1 to 5 do
       begin
       if a<>b then
          begin
          if tab[a,b]=0 then por[a]:=por[a]+1;
          if tab[a,b]=2 then pob[a]:=pob[a]+1;
          end
       else
       end;
   end;

chislo:=0;
for a:=1 to 5 do
if pob[a]>por[a] then chislo:=chislo+1;

writeln;
writeln('Chislo komand, u kotoryh pobed bolshe, chem porazheniy, ravno ',chislo);

readln;

END.
volvo
Lenka, что именно надо перевести в While и Repeat? Все циклы?
Guest
Вместо for должен быть while и еще один экземпляр с repeat.
Lenka
Забыла имя написать rolleyes.gif rolleyes.gif rolleyes.gif

М
А если ты зарегистрирешься то сможешь редактировать свои сообщения и никогда не будет забывать писать имя smile.gif give_rose.gif
Altair

volvo
Ну, прежде чем что-то менять в программе, нужно ее привести в нормальный вид: избавляемся от GoTo и от лишних begin ... end и веток else
program Lab3;
uses crt;

var
  tab:array [1..5,1..5] of integer;
  pob:array [1..5] of integer;
  por:array [1..5] of integer;
  a,b,chislo:integer;

BEGIN

  clrscr;
  for a:=1 to 5 do
    for b:=1 to 5 do begin

      if a=b then tab[a,b]:=0
      else
        repeat
          write('Vvedite znachenie yacheyki (',a,',',b,'): ');
          readln(tab[a,b]);
          if (tab[a,b]<0) or (tab[a,b]>2) then
            writeln('Nevernoe znachenie. Povtorite eshe raz.');
        until (tab[a,b] >= 0) and (tab[a, b] <= 2);
    end;

  writeln;
  writeln('Poluchennaya matritsa:');
  for a:=1 to 5 do
    writeln(tab[a,1],' ',tab[a,2],' ',tab[a,3],' ',tab[a,4],' ',tab[a,5]);

  for a:=1 to 5 do begin

     pob[a]:=0; por[a]:=0;
     for b:=1 to 5 do
       if a<>b then begin

         if tab[a,b]=0 then por[a]:=por[a]+1;
         if tab[a,b]=2 then pob[a]:=pob[a]+1;

       end
  end;

  chislo:=0;
  for a:=1 to 5 do
    if pob[a]>por[a] then chislo:=chislo+1;

  writeln;
  writeln('Chislo komand, u kotoryh pobed bolshe, chem porazheniy, ravno ',
    chislo);
  readln;

END.
Lenka
Все равно не получается. HEEEELP!!!

ГЫ! А я теперь еще и мужчина.

М
мы тоже над этим думали... в профиле поставь то на самом деле есть
Altair

volvo
Цитата
Все равно не получается.

А пробовала? Вот через Repeat:
program Lab3;
uses crt;

var
  tab:array [1..5,1..5] of integer;
  pob:array [1..5] of integer;
  por:array [1..5] of integer;
  a,b,chislo:integer;

BEGIN

  clrscr; a := 1;
  repeat
    b := 1;
    repeat

      if a=b then tab[a,b]:=0
      else
        repeat
          write('Vvedite znachenie yacheyki (',a,',',b,'): ');
          readln(tab[a,b]);
          if (tab[a,b]<0) or (tab[a,b]>2) then
            writeln('Nevernoe znachenie. Povtorite eshe raz.');
        until (tab[a,b] >= 0) and (tab[a, b] <= 2);

      inc(b);
    until  b > 5;

    inc(a);
  until a > 5;

  writeln;
  writeln('Poluchennaya matritsa:');
  a := 1;
  repeat
    writeln(tab[a,1],' ',tab[a,2],' ',tab[a,3],' ',tab[a,4],' ',tab[a,5]);
    inc(a)
  until a > 5;


  a := 1;
  repeat

    pob[a]:=0; por[a]:=0;
    b := 1;
    repeat
      if a<>b then begin

        if tab[a,b]=0 then por[a]:=por[a]+1;
        if tab[a,b]=2 then pob[a]:=pob[a]+1;

      end;
      inc(b);
    until b > 5;
    inc(a)
  until a > 5;

  chislo:=0;
  a := 1;
  repeat
    if pob[a]>por[a] then chislo:=chislo+1;
    inc(a);
  until a > 5;

  writeln;
  writeln('Chislo komand, u kotoryh pobed bolshe, chem porazheniy, ravno ',
    chislo);
  readln;

END.
Lenka
Через while не получается. (наверное я дура)
volvo
Что там может НЕ получаться? Ты знаешь, как цикл While организуется?
Lenka
Я поняла в чем была моя ошибка. Спасибо тебе огромное volvo wub.gif wub.gif wub.gif
Это текстовая версия — только основной контент. Для просмотра полной версии этой страницы, пожалуйста, нажмите сюда.