主题: [MATLAB基础] 循环嵌套的疑问
查看单个帖子
旧 2009-05-17, 23:15   #3
TTT_IOU
普通会员
 
注册日期: 2009-02-22
帖子: 91
声望力: 18
TTT_IOU 正向着好的方向发展
默认 回复: 循环嵌套的疑问

程序中的2k应为2*k,且str_etoile='';
clear all;
x = input('entrer un chiffre entier impair : ');
if mod(x,2)==0
fprintf('%.0f n''est pas un chiffre entier impair \n',x);
else
str_space='';
str_etoile='';
for k=1: (x+1)/2
for n=1: (x-(2*k-1)/2)/2
str_space=strcat(str_space,' ');
end
for n=1: (2*k-1)
str_etoile=strcat(str_etoile,'*');
end
str_result=[str_space str_etoile str_space];
fprintf('%s \n',str_result);
end
end
不过程序中的str_space='';不起作用,因为矩阵对空格不显示;
TTT_IOU 当前离线   回复时引用此帖