"Fixing" a value in a recursive function
1 回表示 (過去 30 日間)
古いコメントを表示
Hi,
I'm trying to use a recursive function to create a specific shape as an output. My function must have only one input. The objective is that my output shows a by x triangle of a specific symbol, such as:
*
**
***
Here is my actual code:
function triangle(x)
if x==1
xc=repmat('*',1,x);
fprintf('%+*s\n',20,xc);
else
triangle(x-1);
xc=repmat('*',1,x);
fprintf('%+*s\n',20,xc);
end
end
I would want the "20" (shown in bold) to be fixed as the initial "x". And not to increment with the recursion occuring.
Thanks
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!