1.
Program exp1 (imput,output);
Var i, s, max: integer;
a :array [1..10] of integer;
begin
for i:=1 to 10 do read (a[i]);
max:=a[1] ;s:=a[1];
for i:=2 to 10 do
begin
if s<0 then s:=0;
s:= s+a[i];
if s>max then max:=s
end;
writeln(‘max=’, max)
end.
输入:-2 13 -1 4 7 8 -1 -18 24 6
输出:max=42
2.
Program exp2 (input,output);
Const n=5;
Var i,j,k : integer;
a : array[1..2*n, 1..2*n] of integer;
Begin
K:=1;
For I:=1 to 2*n-1 do
If i<=n then
if odd(i) then
for j:= I downto 1 do
begin
a [I-j+1,j]:=k; k:=k+1
end
else for j: =1 to i do
begin
a[i-j+1,j]:=k; k:=k+1;
end
else if odd(i) then for j:=n downto I-n+1 do
begin
a[I-j+1,j]:=k; k:=k+1;
end
else for j:=I-n+1 to n do
begin
a[I-j+1,j]:=k; k:=k+1;
end;
for I:=1 to n do
begin
for j:=1 to n do
write(a[I,j]:3);
writeln
end;
end.
输出: 1 3 4 10 11
2 5 9 12 19
6 8 13 18 20
7 14 17 21 24
15 16 22 23 25
3.
Program exp3 (input,output);
Const N=10;
Var
S,I : integer;
Function CO(I1:integer) : integer;
VAR J1,S1 : integer;
Begin
S1:=N;
For J1:= (N-1) downto (N-I1+1) do
S1:= S1*J1 div (N-J1+1);
CO:=S1
End;
Begin
S:=N+1;
For I:= 2 to N do S:=S + CO(I);
Writeln(‘S=’,S);
End.
输出:S=1024
4.
Program exp4(input,output); {12%}
Const N=3;
VAR I,J,S,X :integer;
P :array[0..n+1] of integer;
G :array[0..100] of integer;
Begin
For I := 0 to 100 do G[I]:=0;
P[0]:=0; P[n+1]:=100;
For I:= 1 to n do read (P[I]); readln;
For I:= 0 to n do
For J:= I+1 to N+1 do
G[abs(P[J]-P[I])]:=G[abs(P[J]-P[I])]+1;
S:=0;
For I:=0 to 100 do
If G[I]>0 then begin
Write(I,:4); S:=S+1;
End;
Writeln;
writeln(‘S=’,S);
Writeln(‘input data:’); readln(X);
Writeln(G[x])
End.
输入:10 20 65
input data: 10
输出:10 20 34 45 55 65 80 90 100