循环控制

for n=1:5
    for m=5:-1:1
        A(n,m)=n^2+m^2;
    end
    disp(n)
end

sum=0;
for a=1:500
if (rem(a,3)==0 && rem(a,7)==0)
sum=sum+a;
end
end
sum
low=input('low')
max=input('max')
for s = low:max
     sum = 0;
   for i = 1:s/2
       if rem(s,i) == 0
        sum = sum + i;
       end
   end
   if sum == s
     disp(s)
   end
end
clear;
clc;
sum=0;
n=0;
x=input('Enter a number(end in 0):');
while(x~=0)
    sum=sum+x;
    n=n+1;
    x=input('Enter a number(end in 0):');
end
if(n>0)
    sum
    mean=sum/n
end
price=input('输入商品价格');
switch fix (price/100)
    case{0,1}
        rate=0;
    case{2,3,4}
        rate=3/100;
    case num2cell(5:9)
        rate=5/100;
    case num2cell(10:24)
        rate=8/100;
    case num2cell(25:49)
        rate=10/100;
    otherwise
        rate=14/100;
end
price=price*(1-rate)

function [ f ] = factor( n )
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here
%递归调用
if n<1
f=1
else
f=factor(n-1)*n
end

上一篇:js数组从子级向父级遍历


下一篇:使用Pandas添加列的时候,出现空值(原因是列的格式是Series)