Var n,a1,d,an,s:integer;
procedure p(n,a1,d:integer; var an,s:integer);
begin
if n>1
then begin p(n-1,a1,d,an,s); an:=an+d; s:=s+an; end
else begin an:=a1; s:=a1; end;
end;
begin
writeln('n, a1, d:');
readln(n,a1,d);
p(n,a1,d,an,s);
writeln('an = ',an,' s = ',s);
end.
Пример:
n, a1, d:
5 34 -2
an = 26 s = 150