cliquez sur l'image pour l'agrandir
program BP09S1;
uses wincrt;
type
tab= array [1..30] of integer;
var
T,TS: tab;
N,K: integer;
procedure saisie (var N,K: integer);
begin
write('N= ');
repeat
readln(N);
until (N in [5..30]);
write ('K= ');
repeat
readln(K);
until (K in [2..N-1])
end;
procedure remplir (var T: tab; N: integer);
var i: integer;
begin
for i:=1 to N do
begin
write ('T[',i,']= ');
repeat
readln(T[i]);
until (T[i]>0)
end;
end;
procedure somme (var TS: tab; T: tab; N,K: integer);
var i,j,S: integer;
begin
for i:=1 to (N-K+1) do
begin
S:=0;
for j:=i to (i+K-1) do
S:=S+T[j];
TS[i]:=S;
end;
end;
procedure afficher (T: tab; N: integer);
var i: integer;
begin
for i:=1 to N do
write(T[i],' ');
end;
begin
saisie(N,K);
remplir(T,N);
somme(TS,T,N,K);
afficher(Ts,N-K+1);
end.
Aucun commentaire:
Enregistrer un commentaire