ex1001.m
来自「数字信号处理的MATLAB实现」· M 代码 · 共 25 行
M
25 行
%例10-1 脚本M文件实例
%Find the prime numbers between 10 and 1000
%clear the workspace
clear
%result save the prime numbers.
result=[];
%for-loop
for i=10:1000
%define a variable which is used to mark whether i is a prime number
mark=1;
%check whether i is a prime number
for j=2:i-1
if mod(i,j)==0
mark=0;
break
end
end
%add prime number to result
if mark==1
result=[result i];
end
end
%output
result
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?