博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

打印图形练习参考程序

Posted on 2010-10-07 11:31  桃子在路上  阅读(194)  评论(0编辑  收藏  举报

program expicture1_1;
const lines = 4;
var
 i, j : integer;
begin
 for i := 1 to lines do
 begin
  write(' ' : i);
  for j := 1 to 2*(lines-i)+1 do
   write('#');
  writeln;
 end;
 readln;
end.


program expicture1_1;
const MaxChar = 7;
var
     i, j : integer;
begin
        i := MaxChar;
        while i >= 1 do
        begin
             for j := 1 to i do
                 write('#');
             writeln;
             i := i-2;
             write(' ' : (MaxChar-i) div 2);
        end;
        readln;
end.

program expicture2_1;
const lines = 7;
var
     i, j : integer;
     ch : char;
begin
        ch := '*';
        for i := 1 to lines do
        begin
             if i <= (lines+1) div 2 then
             begin
                  write(' ' : (lines+1) div 2 -i+1);
                  for j := 1 to 2*i-1 do
                      write(ch);
             end
             else
             begin
                  write(' ' : i-lines div 2);
                  for j := 1 to 2*(lines-i)+1 do
                      write(ch);
             end;
             writeln;
             if ch = '*' then
                 ch := '+'
             else
                 ch := '*';
        end;
        readln;
end.

program expicture2_1;
const lines = 7;
var
     i, j : integer;
     ch : char;
begin
        ch := '*';
        for i := lines div -2 to lines div 2 do
        begin
             write(' ' : abs(i)+1);
             for j := 1 to lines-2*abs(i) do
                  write(ch);
             writeln;
             if ch = '*' then ch := '+' else ch := '*';
        end;
        readln;
end.

program expicture3_1;
const lines = 5;
var
     i, j, k : integer;
begin
        k := (lines+1) div 2;
        for i := 1 to (lines+1) div 2 do
        begin
             write(' ' : (lines+1) div 2 -i+1);
             for j := 1 to 2*i-1 do
                  write(k);
             if i mod 2 = 0 then k := k-1;
             writeln;
        end;
        for i := lines div 2 downto 1 do
        begin
             write(' ' : (lines+1) div 2 -i+1);
             for j := 1 to 2*i-1 do
                  write(k);
             if i mod 2 = 0 then k := k-1;
             writeln;
        end;
        readln;
end.

program expicture3_2;
const lines = 5;
var
     i, j, k : integer;
begin
        k := (lines+1) div 2;
        for i := -k+1 to k-1 do
        begin
             write(' ' : abs(i)+1);
             for j := 1 to lines-2*abs(i) do
                  write(k);
             if (i+1 - lines div -2) mod 2 = 0 then k := k-1;
             writeln;
        end;
        readln;
end.

program expicture3_1;
const lines = 5;
var
     i, j, k : integer;
begin
        k := (lines+1) div 2;
        for i := 1 to (lines+1) div 2 do
        begin
             write(' ' : (lines+1) div 2 -i+1);
             for j := 1 to 2*i-1 do
                  write(k);
             if i mod 2 = 0 then k := k-1;
             writeln;
        end;
        for i := lines div 2 downto 1 do
        begin
             write(' ' : (lines+1) div 2 -i+1);
             for j := 1 to 2*i-1 do
                  write(k);
             if i mod 2 = 0 then k := k-1;
             writeln;
        end;
        readln;
end.

program expicture3_2;
const lines = 5;
var
     i, j, k : integer;
begin
        k := (lines+1) div 2;
        for i := -k+1 to k-1 do
        begin
             write(' ' : abs(i)+1);
             for j := 1 to lines-2*abs(i) do
                  write(k);
             if (i+1 - lines div -2) mod 2 = 0 then k := k-1;
             writeln;
        end;
        readln;
end.

program expicture5_1;
const lines = 5;
var
     i, j : integer;
begin
        for i := 1 to lines do
        begin
             write(' ' : lines-i+1);
             for j := 1 to i do
                 write(i-j);
             for j := i-1 downto 1 do
                 write(i-j);
             writeln;
        end;
        readln;
end.

 

program expicture5_2;
//const lines = 5;
var
     i, j, lines : integer;
begin
        write('Please enter a number: ');
        readln(lines);
        for i := 1 to lines do
        begin
             write(' ' : lines-i+1);
             for j := -i+1 to i-1 do
                 write(abs(j));
             writeln;
        end;
        readln;
end.

 

program expicture5_3;
var
     i, j : integer;
     lines : integer;
begin
        write('Please enter a number: ');
        readln(lines);
        lines := lines+1;
        for i := 1 to lines do
        begin
             write(' ' : lines-i+1);
             for j := 1 to i do
                 write(i-j);
             for j := i-1 downto 1 do
                 write(i-j);
             writeln;
        end;
        readln;
end.

program expicture6_1;
var
     i, j : integer;
     lines : integer;
begin
        write('Please enter a number: ');
        readln(lines);
        for i := lines div -2 to lines div 2 do
        begin
             write(' ' : abs(i)+1);
             for j := 1 to lines-2*abs(i) do
                  write((lines+1) div 2 -abs(i));
             writeln;
        end;
        readln;
end.


program expicture6_2;
const lines = 5;
var
     i, j : integer;
begin
        for i := 1 to lines do
        begin
             if i <= (lines+1) div 2 then
             begin
                  write(' ' : (lines+1) div 2 -i+1);
                  for j := 1 to 2*i-1 do
                      write(i);
             end
             else
             begin
                  write(' ' : i-lines div 2);
                  for j := 1 to 2*(lines-i)+1 do
                      write(lines-i+1);
             end;
             writeln;
        end;
        readln;
end.

program expicture7_1;
const lines = 4;
var
     i, j : integer;
begin
        for i := 1 to lines do
        begin
             write(' ' : lines-i+1);
             for j := 1 to 2*i-1 do
                  write('*');
             if lines > i then write(' ' : (lines-i)*2);
             for j := 1 to 2*i-1 do
                  write('*');
             if lines > i then write(' ' : (lines-i)*2);
             for j := 1 to 2*i-1 do
                  write('*');
             writeln;
        end;
        readln;
end.