新手:题目是“生成相量 A,其元素为区间[1,999]内的整数,然后找出 A 中能被 13 整除且 大于 500 的数。”

52 views (last 30 days)
新百胜游戏账号注册网址www.xbs0733.vip
Answered: Xiaotong WU on 12 Aug 2022
A=[1:999];
j=1;
i=A
for i=A
if A(i)>500;
if rem(A(i),13)==0;
C(j)=A(i);
j=j+1;
end
end
end
disp(C)
请问从if语句就开始不懂为什么用A(i),还有C(j)的意义是什么
  1 Comment
新百胜游戏账号注册网址www.xbs0733.vip
A=[1:999];
j=1;
i=A
for i=A
if A(i)>500;
if rem(A(i),13)==0;
C(j)=A(i);
j=j+1;
end
end
end
disp(C)

Sign in to comment.

Answers (1)

Xiaotong WU
Xiaotong WU on 12 Aug 2022
用来把筛选的结果存在C向量里,代码有点冗余,可以参考:
C=[];
for i=500:999
if rem(i,13)==0
C=[C;i];
end
end
disp(C)
507 520 533 546 559 572 585 598 611 624 637 650 663 676 689 702 715 728 741 754 767 780 793 806 819 832 845 858 871 884 897 910 923 936 949 962 975 988

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!