你好,代码供参考:
dia函数
function dia(x)
str = repmat(char(32), 1, 4*x-3);
for i = 1:x-1
estr = str;
estr(2*x+2*i-3) = '*';
estr(2*x-2*i+1) = '*';
fprintf('%s\n', estr)
end
str(1,1:4:end) = '*';
fprintf('%s\n', str)
end
diamov函数
function diamov(x)
for i = 3:x
fprintf('dia(%d)\n', i);
dia(i)
end
end
效果:
diamov(10)
dia(3)
*
* *
* * *
dia(4)
*
* *
* *
* * * *
dia(5)
*
* *
* *
* *
* * * * *
dia(6)
*
* *
* *
* *
* *
* * * * * *
dia(7)
*
* *
* *
* *
* *
* *
* * * * * * *
dia(8)
*
* *
* *
* *
* *
* *
* *
* * * * * * * *
dia(9)
*
* *
* *
* *
* *
* *
* *
* *
* * * * * * * * *
dia(10)
*
* *
* *
* *
* *
* *
* *
* *
* *
* * * * * * * * * *
如有帮助,还望题主给个宝贵的采纳支持一下,谢谢啦