In: Computer Science
Create a random matrix of size 10x10, of integers between 1 and 1000, and use nested for loops over the elements of the matrix to find the number of prime elements , as well as the sum of the prime elements in the matrix.
There are .... prime numbers and their sum is ...
MATLAB CODE:-
a=1;
b=1000;
cnt=0;
sm=0;
z = randi([1 1000],10,10)
for i=1:10
for j=1:10
if isprime(z(i,j))
cnt=cnt+1;
sm=sm+z(i,j);
end
end
end
cnt
sm
fprintf('there are %d prime numbers and their sum is
%d',cnt,sm)
editor window screenshot: checks prime numbers and finds their sum
result window screenshot:
kindly comment for further elaboration..please like if you find it needfull...