作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何制作这个图案?
您会看到下面有一个十字图案(打印在空间中)
********
* ****** *
** **** **
*** ** ***
**** ****
**** ****
*** ** ***
** **** **
* ****** *
********
这是我尝试过的。为了测试目的,我将用户输入值设置为 10。
uses crt;
var a,b,n,space1,space2 : integer;
begin
clrscr;
n:= 10;
space1:=1;
space2:=n;
for a:=1 to n do
begin
for b:=1 to n do
begin
if(b=space1) OR (b=space2-1) then
begin
write(' ');
space1:=space1+1;
space2:=space2-1;
end else
write('*');
end;
writeln;
end;
readkey;
我在打印空格字符时遇到问题。
我认为问题出在 if 条件上。
这种情况的最佳条件是什么?
最佳答案
您正在寻找的功能是
StringOfChar(c: char, i: SizeInt): AnsiString
示例:创建 5 *
var s: string;
..
s := StringOfChar('*', 5);
..
为了获得进一步的帮助,您应该在您的工作中提供一些示例代码。
一种方法是:
uses crt;
var a,b,n,space1,space2 : integer;
s: string;
begin
clrscr;
n:= 10;
// first half of cross
for a:=0 to n div 2 -1 do begin
s := StringOfChar('*', n-2);
Insert(' ', s, a+1); // first space
Insert(' ', s, n-a); // last space
writeln(s);
end;
// second half of cross
for a:= (n div 2 -1) downto 0 do begin
s := StringOfChar('*', n-2);
Insert(' ', s, a+1); // first space
Insert(' ', s, n-a); // last space
writeln(s);
end;
writeln;
readkey;
end.
您也可以只用一个循环来解决这个问题。
我把它留给你作为学习练习:-)
关于pascal - 如何在Pascal中使十字形图案与用户输入相对应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33775717/
我是一名优秀的程序员,十分优秀!