参考代码:
N=randi(100,1,50)
M=N(isprime(N))
M=sort(M,'descend')
sum(M)
某次运行结果(有随机数,每次运行结果不同):
>> N=randi(100,1,50)
N =
Columns 1 through 9
80 81 6 41 97 42 34 64 86
Columns 10 through 18
79 54 75 74 45 86 50 95 80
Columns 19 through 27
14 24 13 54 6 47 99 69 88
Columns 28 through 36
50 29 19 97 76 96 68 19 29
Columns 37 through 45
6 5 28 18 68 91 36 11 80
Columns 46 through 50
47 69 69 43 66
>> M=N(isprime(N))
M =
Columns 1 through 9
41 97 79 13 47 29 19 97 19
Columns 10 through 14
29 5 11 47 43
>> M=sort(M,'descend')
M =
Columns 1 through 9
97 97 79 47 47 43 41 29 29
Columns 10 through 14
19 19 13 11 5
>> sum(M)
ans =
576