a=[4 -1 2 -8 4 5 -3 -1 6 -6];
i=1;
s=0;
while i<10
if a(i)>0
s=s+a(i);
end
i=i+1;
end
s
按理来说和应该是16,怎么算出来的是21呢
a=[4 -1 2 -8 4 5 -3 -1 6 -6];
i=1;
s=0;
while i<10
if a(i)>0
s=s+a(i);
end
i=i+1;
end
s
你好同学,你的数组里面正数元素相加即4+2+4+5+6=21,所以并不是你想的16呢,MATLAB计算的是对的
有帮助望采纳呢,谢谢啦mua~