回复: 循环嵌套的疑问
程序中的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='';不起作用,因为矩阵对空格不显示;
|