matlab 编写一个函数,求输入数据中,所有质数的和,求大佬帮忙,最好留一下程序,谢谢

2024-12-31 01:06:19
推荐回答(1个)
回答1:

function Prime_Numbers_Sun(a)
x1 = floor(a);
count = 1;
for i = 1: x1
if isprime(i) == 1
y1(count) = i;
count = count + 1;
end
end
S = sum(y1);
txt = ['从0到',num2str(a),'之间的所有质数和为',num2str(S)];
disp(txt)