主页 > 氮气弹簧螺丝之家

pascal:a+b

306 2023-08-01 17:10

一、pascal:a+b

var a,b,s:integer;

begin

read(a,b);

s:=a+b;

write('a+b=',s);

end.

二、free pascal

求阶乘吧

var

n, i, res: Integer;

begin

Readln(n);//输入n

res := 1;

for i := 1 to n do

res := res * i;//乘积

Writeln(res);

end.

三、Turbo pascal

var
n,a,b:integer;

begin
readln(n);
a:=n mod 10;
writeln(a);
b:=n div 10;
writeln(b);
readln;

end.

四、蛇行方阵 pascal

program like006;

var

a:array[1..20,1..20] of integer;

c,t,k,r,n:integer;

begin

writeln('n=');

read(n);

t:=1;k:=1;

for r:=1 to n do

for c:=1 to n do

a[r,c]:=0;

r:=1;c:=1;t:=2;a[1,1]:=1;

while (t<=n*n) do

case k of

1: begin

r:=r+1;

a[r,c]:=t;

t:=t+1;

if c=1 then k:=3;

if c=n then k:=4;

end;

2: begin

c:=c+1;

a[r,c]:=t;

t:=t+1;

if r=1 then k:=4;

if r=n then k:=3;

end;

3: begin

r:=r-1;

c:=c+1;

a[r,c]:=t;

t:=t+1;

if (r=1) then k:=2;

if (c=n) then k:=1;

end;

4: begin

r:=r+1;

c:=c-1;

a[r,c]:=t;

t:=t+1;

if (r=n) then k:=2;

if (c=1)and(r<>n) then k:=1;

end;

end;

for r:=1 to n do

begin

for c:=1 to n do

write(a[r,c]:4);

writeln;

end;

readln;

readln

end.