Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#3 |
普通会员
注册日期: 2009-02-22
帖子: 91
声望力: 18 ![]() |
![]()
程序中的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='';不起作用,因为矩阵对空格不显示; |
![]() |
![]() |