Best Answer

My Code:

======================================…

>>

disp('input a pair of natural numbers, N and M with M>N');

N=input('N=');

M=input('M=');

for j=0:(M-N)

Prime=1;

for i=2:((N+j)/2)

if mod((N+j),i)==0

Prime=0;

break

end

end

if Prime==1

disp('This is a Prime number');

else disp('Not Prime');

end

end

Q: How do you write a matlab code to check if a random number is prime or not?

Write your answer...

Submit

Still have questions?

Continue Learning about Math & Arithmetic

Prime numbers have many applications. Some examples are: public key cryptography, hash tables, pseudo-random number generators, and ISBN check digits.

A prime number can only be divided by itself and 1

Find a prime number, add 2 to the number. Check if the new number is prime. IE : 3 is prime. 3+2 =5. 5 is prime. (3,5) are twin primes.

13

You divide the number by 2. If the number is able to divide WITHOUT a remainder, then it is a prime number. If you divide a number by 1, you will get the same number. That is not a prime number.

Related questions

no, 19 is a prime number and it is not even. just a random example.

No, it is not. You can check on prime-numbers.org

No its not a prime number Check out related links

Prime numbers have many applications. Some examples are: public key cryptography, hash tables, pseudo-random number generators, and ISBN check digits.

A prime number can only be divided by itself and 1

Find a prime number, add 2 to the number. Check if the new number is prime. IE : 3 is prime. 3+2 =5. 5 is prime. (3,5) are twin primes.

13

the largest prime number under 100 is 97

You divide the number by 2. If the number is able to divide WITHOUT a remainder, then it is a prime number. If you divide a number by 1, you will get the same number. That is not a prime number.

A prime number is any number that only has one and itself as factors. Threfore, any number taht has more than two factors is not prime. Check the the factors of a number to tell if it is prime or not.

A prime number is any number that only has one and itself as factors. Threfore, any number taht has more than two factors is not prime. Check the the factors of a number to tell if it is prime or not.

A prime number is any number that only has one and itself as factors. Therefore, any number that has more than two factors is not prime. Check the the factors of a number to tell if it is prime or not.