Offer

编程类-----matlab基础语法复习(2)

  2019年美赛准备:matlab基本题目运算

    

clear,clc
%% 计算1/3 + 2/5 + ...3/7 +10/21
% i = 1; j = 3; ans = 0;
% while i <= 10
%     ans = ans + i / j;
%     i = i + 1;
%     j = j + 2;
% end
% disp('上述结果为:')
% ans

% sum((1:10)./(3:2:21))

%% 1到100内能被3和7整除的数之和
ans = 0;
for i = 1:100
    if mod(i, 3) == 0 && mod(i, 7) == 0
        ans = ans + i;
    end
end
disp('上述结果为:')
ans

  

posted @ 2019-01-17 15:55  Empirefree  阅读(173)  评论(0编辑  收藏  举报