pascal 输入n(1<=n<=20),输出n*n的矩阵,且按照一定的规律。
例如,输入3,则输出如下的矩形:123456789样例输入SampleInput5样例输出SampleOutput1234567891011121314151617181...
例如,输入3,则输出如下的矩形:1 2 3
4 5 6
7 8 9
样例输入 Sample Input
5
样例输出 Sample Output 1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25 展开
4 5 6
7 8 9
样例输入 Sample Input
5
样例输出 Sample Output 1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25 展开
3个回答
2013-08-05
展开全部
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils;
procedure doRect(n:Integer);
var i, j, r:longint;
begin
r:=1;
for i:=0 to n-1 do begin
for j:=1 to n do begin
write(i*r+j:3);
end;
writeln('');
r:=r+1;
end;
end;
var n:longint;
begin
Writeln('Input a num and Press ENTER:');
read(n);
doRect(n);
Writeln('Input a num and Press ENTER to exit');
read(n);
end.
展开全部
var
n,i,j:longint;
begin
readln(n);
for i:=1 to n do
begin
for j:=1 to n-1 do write((i-1)*n+j,' ');
writeln(i*n);
end;
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
var
i,j,k,o,p,n,m:longint;
a:array[1..9,1..9]of longint;
begin
i:=1; j:=1; k:=1;
read(n);
while k<=n*n do
begin
a[i,j]:=k;
dec(i); inc(j); inc(k);
if (i=0) or (j=n+1) then
begin
i:=i+j; j:=1;
if i>n then
begin
j:=1+i-n;i:=n;
end;
end;
end;
for i:=1 to n do
for j:=1 to n do
if j=n then writeln(a[i,j]:3) else write(a[i,j]:3);
end.
i,j,k,o,p,n,m:longint;
a:array[1..9,1..9]of longint;
begin
i:=1; j:=1; k:=1;
read(n);
while k<=n*n do
begin
a[i,j]:=k;
dec(i); inc(j); inc(k);
if (i=0) or (j=n+1) then
begin
i:=i+j; j:=1;
if i>n then
begin
j:=1+i-n;i:=n;
end;
end;
end;
for i:=1 to n do
for j:=1 to n do
if j=n then writeln(a[i,j]:3) else write(a[i,j]:3);
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询