Консультация № 122626
11.02.2008, 10:42
0.00 руб.
0 1 1
Указатели
Написать процедуру или функцию, которая находит среднее арифметическое непустого списка L.

Обсуждение

Неизвестный
11.02.2008, 14:25
общий
это ответ
Здравствуйте, Jkalamari!
Программа в приложении.

Удачи!

Приложение:
type PElem = ^TElem; TElem = record value : integer; next : PElem; end;function summList(el:PElem):integer;var res : integer;begin res := 0; while el^.next <> nil do begin res := res + el^.value; el := el^.next; end; res := res + el^.value; summlist := res;end; procedure Add(var el : PElem; a : integer);var p : PElem;begin new(p); p^.next := el; p^.value := a; el := p;end;var el : PElem; a, count : integer;begin count := 0; repeat WriteLn(‘Input number (or "-1" to count):‘); ReadLn(a); if a <> -1 then begin Add(el,a); count := count + 1; end; until a = -1; WriteLn(‘Summa: ‘, SummList(el)); WriteLn(‘Srednee: ‘,(SummList(el)/count):1:2);; ReadLn;end.
Форма ответа