MatLab Write a function called primes that takes two positiv

MatLab
Write a function called primes that takes two positive integers m and n as input arguments, and returns vector containing all the prime numbers between m and n. if m>n, then an empty vector is returned.

the function will be invoked as follows:

vec = primes (m, n);

do not use isprime

Solution

function [prime] = Prime_Num(n,m)
if (n>m || n <0 || m < 0)
error(\'ERROR: Invalid Input\');
end
prime = [];
for i=0:(m-n)
if all(mod((n+i),2:((n+i)/2))), prime = [prime;n+i]; end
end

MatLab Write a function called primes that takes two positive integers m and n as input arguments, and returns vector containing all the prime numbers between m

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site